2
一個功能需要整組args來傳遞成也接受參數的個數的變量#,例如另一功能(以下不工作):如何將所有可變數量的參數傳遞給接受可變數量參數的另一個函數?接受參數的個數的變量#
debugConsole : function(msg) {
if(this.isDebugOn()) {
console.log(arguments); // does not work, prints "[object Arguments]"
}
}
我需要這使字符串替換的console.log的()功能的工作原理,即
var myObject = {name: "John Doe", id: 1234};
// should print "obj = [object Object]"
this.debugConsole("myObject = %o", myObject);
// should print "name: John Doe, ID: 1234"
this.debugConsole("name: %s, ID: %i", myObject.name, myObject.id);