J
JavascriptProgrammer
In the following code:
-----------------------
function get() {
return function() {
alert(x);
}
};
function foo(s) {
var x = s;
this.getX = get();
}
var f = new foo("hello");
f.getX()
--------------------------
Instead of printing "hello", f.getX() gives a JS error
of ("x is not defined").
Can someone explain Why in detail ?
-----------------------
function get() {
return function() {
alert(x);
}
};
function foo(s) {
var x = s;
this.getX = get();
}
var f = new foo("hello");
f.getX()
--------------------------
Instead of printing "hello", f.getX() gives a JS error
of ("x is not defined").
Can someone explain Why in detail ?