The out put is 12 12 for the following code.
var omg = function(){
var space = {q:12} ;
var sq = [];
sq[0] = function(){
console.log(space.q);
space.q = 14;
};
sq[1] = function(){
console.log(space.q);
};
return sq;
};
omg()[0]();
omg()[1]();
~
Why is the output not 12 14 ?!?
Each
omg()call returns a new function. Hence, theomg()[0]()call changes the local value ofqof that particular instance. I think if you did it like this:you’d get the expected output.