我有一个任意值的数组。我编写了一个函数,将该数组转换为返回原始值的函数数组,因此不再调用a[3],而是调用a3。
这是我的代码,但它无法工作?code。它会报错“Cannot call method '1' of undefined”。
这是我的代码,但它无法工作?code。它会报错“Cannot call method '1' of undefined”。
var numToFun = [1, 2, { foo: "bar" }];
var numToFunLength = numToFun.length;
function transform(numTo) {
for (var i = 0; i < numToFunLength; i++) {
(function(num){
numTo.unshift(function() {
return num;
});
}(numTo.pop()))
}
}
var b = transform(numToFun);
console.log(numToFun);
console.log(b[1]());