0
我有一个定制的(控制台)日志功能传递数组作为参数列表中的元素到一个功能(未作为组合的字符串)
function clog(toConsole, toFile){
console.log(toConsole);
// other things
}
但现在我无法通过它在串'value: %d', value
格式
...除非我把它包在一个数组
clog(['to console: %d', value], 'other things'])
有没有办法给数组['to console: %d', value]
的元素传递给像一个函数:console.log('to console: %d', value)
你在找这个? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply 例如, 'yourFunction.apply(this || window,yourArrayOfArguments);' –