Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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,我是Javascript的新手,创建了一个示例函数来测试Javascript的apply函数 我需要澄清一下这个代码 value-x将取第一个数组['val1','val2'],但只是想知道它是否替换为(这个,x)。。 2.我看到console.log中打印了3项,最后一项是-未定义,未定义,发生了什么 var dummyfunction1 = function(val1,val2){ console.log(array1,array2); }; [['val1','val2'],['

我是Javascript的新手,创建了一个示例函数来测试Javascript的apply函数

我需要澄清一下这个代码

  • value-x将取第一个数组['val1','val2'],但只是想知道它是否替换为(这个,x)。。 2.我看到console.log中打印了3项,最后一项是-未定义,未定义,发生了什么

    var dummyfunction1 = function(val1,val2){
        console.log(array1,array2);
    };
    
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });
    
    dummyfunction1()
    

  • 这里有几个问题

    dummyfunction1正在使用主体中未定义的变量。应该是这样的:

    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    // this will automatically be run, no need to call dummyfunction1 on your own after this
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });
    
    最后一行
    dummyfunction1()
    正在对dummyfunction1进行无参数的附加调用。这是您看到的未定义的

    完整代码如下所示:

    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    // this will automatically be run, no need to call dummyfunction1 on your own after this
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });
    

    这里有几个问题

    dummyfunction1正在使用主体中未定义的变量。应该是这样的:

    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    // this will automatically be run, no need to call dummyfunction1 on your own after this
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });
    
    最后一行
    dummyfunction1()
    正在对dummyfunction1进行无参数的附加调用。这是您看到的未定义的

    完整代码如下所示:

    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    // this will automatically be run, no need to call dummyfunction1 on your own after this
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });
    

    这里有几个问题

    dummyfunction1正在使用主体中未定义的变量。应该是这样的:

    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    // this will automatically be run, no need to call dummyfunction1 on your own after this
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });
    
    最后一行
    dummyfunction1()
    正在对dummyfunction1进行无参数的附加调用。这是您看到的未定义的

    完整代码如下所示:

    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    // this will automatically be run, no need to call dummyfunction1 on your own after this
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });
    

    这里有几个问题

    dummyfunction1正在使用主体中未定义的变量。应该是这样的:

    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    // this will automatically be run, no need to call dummyfunction1 on your own after this
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });
    
    最后一行
    dummyfunction1()
    正在对dummyfunction1进行无参数的附加调用。这是您看到的未定义的

    完整代码如下所示:

    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    var dummyfunction1 = function(val1,val2){
        console.log(val1,val2);
    };
    
    // this will automatically be run, no need to call dummyfunction1 on your own after this
    [['val1','val2'],['val3','val4']].forEach(function(x){
        dummyfunction1.apply(this,x);
    });