javascript - How to access a variable state from the defining function rather than the calling object -


eg:

func = (){      var i_want_this = "yes";      var callback = function(){         // want access value of i_want_this here         // preferably single variable without whole scope     };      obj.subfunc(some_stuff, callback);  };   obj = {      subfunc = function(stuff, callback){          // stuff          callback();      }  };  func(); 

you can use variable in callback; work way want to.

this called closure.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -