我有一个带有参数的函数,例如:
function doThisThing(toThis){
// some function
}
到目前为止,我已经使用不同的参数多次调用该函数,如下所示:
doThisThing ( bananas );
doThisThing ( apples );
doThisThing ( pears );
有没有更简洁的方法?我试过 doThisThing ( bananas, apples, pears );
等等,但无济于事......
最佳答案
[bananas, apples, pears].forEach(doThisThing);
如果您可以依赖 Array.prototype.forEach
支持并且 doThisThing
只接受一个参数,则可以工作。
关于javascript - 在 JavaScript/jQuery 中多次调用带有参数的函数的简写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26171386/