Javascript 如何从定义函数而不是调用对象访问变量状态
例如:Javascript 如何从定义函数而不是调用对象访问变量状态,javascript,Javascript,例如: 您可以在回调中使用该变量;它会按照你想要的方式工作 这称为a。您可以在回调中使用该变量;它会按照你想要的方式工作 这称为。您没有尝试运行代码,是吗?您没有尝试运行代码,是吗? func = (){ var i_want_this = "yes"; var callback = function(){ // I want to access value of i_want_this here // Preferably just the
您可以在回调中使用该变量;它会按照你想要的方式工作
这称为a。您可以在回调中使用该变量;它会按照你想要的方式工作
这称为。您没有尝试运行代码,是吗?您没有尝试运行代码,是吗?
func = (){
var i_want_this = "yes";
var callback = function(){
// I want to access value of i_want_this here
// Preferably just the single variable without the whole scope
};
obj.subfunc(some_stuff, callback);
};
obj = {
subfunc = function(stuff, callback){
// do stuff
callback();
}
};
func();