假设我有数组 [func1, func2, func3]。
我想打印为字符串:“func1, func2, func3”。但是,它会打印函数的全部内容。
我需要做一些正则表达式来从输出中获取名称还是有更简单的方法?
干杯。
假设我有数组 [func1, func2, func3]。
我想打印为字符串:“func1, func2, func3”。但是,它会打印函数的全部内容。
我需要做一些正则表达式来从输出中获取名称还是有更简单的方法?
干杯。
您想在列表中获取函数名称,对吗?如果是这样的话,这样的事情应该对你有用。如果这不是你想做的,请告诉我。 JsFiddle 工作代码在这里
//declare the dummy functions
function funcOne(){
return null;
}
function funcTwo(){
return null;
}
function funcThree(){
return null;
}
//add the functions to the array
var functionArray=[funcOne,funcTwo,funcThree];
//declare an output array so we can then join the names easily
var output=new Array();
//iterate the array using the for .. in loop and then just getting the function.name property
for(var funcName in functionArray){
if(functionArray.hasOwnProperty(funcName))
output.push(functionArray[funcName].name);
}
//join the output and show it
alert(output.join(","));