我有这样的功能。
function myfun(input1, input2, input3){
//
// Other codes which deals with input2 and input3 (irrelevant)
//
function a(){
console.log('func a');
}
function b(){
console.log('func b');
}
function c(){
console.log('func c');
}
function d(){
console.log('func d');
}
// input1 is an array
for(var i=0; i<input1.length; i++){
var name = input1[i];
name(); // Doesn't work as 'name' refers to a string;
this[name](); // Doesn't work;
// How can i execute the nested function whose name is stored in input array ?
}
}
myfun(['b','d'], 'foo', 'bar');
如何调用名称在 input1 数组中给出的嵌套函数?
谢谢你。