我正在閱讀關於js中的調用函數。 現在我有這樣的代碼JavaScript中的調用函數給出錯誤
var o = {
name: 'i am object',
age: 22
}
function saymyName(arguentToFunc) {
console.log('my name is ' + this.name + 'and thw argument passed is ' + arguentToFunc);
}
saymyName.apply(o, 'hello there');
但它給出了一個錯誤信息說Uncaught TypeError: Function.prototype.apply: Arguments list has wrong type
在這本書是寫在明確的指南,第二個參數是傳遞給價值功能。例如這裏它是hello there
那麼爲什麼錯誤呢?
嘿根據書 。 apply needs this
如果一個函數被定義爲接受任意數量的參數,意味着什麼?我的意思是arbrital?
嘿爲什麼我downvoted? –
@耶,但我很困惑! –