closure not working
Posted
by dorelal
on Stack Overflow
See other posts from Stack Overflow
or by dorelal
Published on 2010-04-07T18:34:00Z
Indexed on
2010/04/07
18:43 UTC
Read the original article
Hit count: 134
JavaScript
var Dog = function() {
var _instance = 'hello world';
return function() {
console.log(this._instance);
}
} (); //note that it is self invoking function
var l = new Dog(); //#> undefined
In the above case I was expecting output of 'hello world'.
Why this._instance is not accessing the the varible which should be accessible by virtue of closure. I tested this in FF and am getting undefined.
© Stack Overflow or respective owner