Mozilla Developer Network這是原始鏈接。如何理解一個關於Array.prototype.copyWithin()的例子?
我在學習MDN的Array.prototype。現在,我對Array.prototype.copyWithin()的一個例子感到困惑。請幫助我,謝謝你的幫助。
例如,下面的代碼可能被我忽略,運行的答案等於我的答案。我認爲第一個代碼像第二個代碼一樣被低估。所以,我知道答案。
console.log([].copyWithin.call(new Int32Array([1, 2, 3, 4, 5]), 0, 3, 4)); // TypedArray => [4, 2, 3, 4, 5]
console.log(new Int32Array([1, 2, 3, 4, 5]).copyWithin(0,3,4)); // TypedArray => [4, 2, 3, 4, 5]
但是,下一個代碼,我無法理解。
console.log([].copyWithin.call({length: 5, 3: 1}, 0, 3)); // How to execute?
這些實例是從Mozilla的開發人員網絡。
我明白了。當代碼像'[] .copyWithin.call(Object,arguments)'時,copyWithin()的參數是Object的關鍵。參數不是數組,而是參數是數組的索引。我之前對Array的理解很狹窄,非常感謝。 – Huooo