Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从定义函数而不是调用对象访问变量状态_Javascript - Fatal编程技术网

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();