应用函数javascript循环额外
我是Javascript的新手,创建了一个示例函数来测试Javascript的apply函数 我需要澄清一下这个代码应用函数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'],['
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);
});