绑定到对象上的copyWithin方法
生活随笔
收集整理的這篇文章主要介紹了
绑定到对象上的copyWithin方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對于在數組上使用copyWithin方法應該都很熟悉,但是綁定到對象上呢?
[].copyWithin.call({length: 5, 3: 1}, 0, 3)I just began to learn JavaScript, and I have no idea how to understand the following code
[].copyWithin.call({length: 5, 3: 1}, 0, 3) // {0: 1, 3: 1, length: 5}通過call方法,對象{length: 5, 3: 1}擁有了copyWithin,
通過call() 方法接受的是0,3參數列表
如果是數組的話:
我想這里的{ length: 5, 3: 1 }應該是類數組對象
Array.from({ length: 5, 3: 1 }) (5) [undefined, undefined, undefined, 1, undefined]0: undefined1: undefined2: undefined3: 14: undefinedlength: 5__proto__: Array(0)通過上面的解釋,再去實現:
{ length: 5, 3: 1 }.copyWithin(0, 3)將三號位上的1 ,和四號位的undefind 復制給0號位,1號位
就得出: {0: 1, 3: 1, length: 5}
總結
以上是生活随笔為你收集整理的绑定到对象上的copyWithin方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 粮食股票,十大粮食龙头股票一览
- 下一篇: 记录一次withRouter的实际应用场