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
Post a Comment