我願做這樣的事情:更改的第一個參數的函數
function start(){
// Change the first argument in the argument list
arguments[0] = '<h1>' + arguments[0] + '</h1>';
// Call log with the new arguments
// But outputs: TypeError: Illegal invocation
log.apply(this, arguments);
}
function log(){
console.log(arguments);
// should output -> ['<h1>hello<h1>', 'world', '!']
}
start('hello', 'world', '!');
注意'print'是已經是一個內置的功能。 –
@Waleed Khan謝謝,我編輯了這個問題。 – Adam
當你傳遞給apply函數時,'arguments'不是一個數組可能會導致一個問題:_The arguments對象不是一個Array。它類似於一個數組,但沒有任何數組屬性,除了length._ - https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments – banzomaikaka