js这段利用apply合并数组的代码没看懂

求大佬详细说下下面代码的运行机制。

(这让我想到了好像以前就是利用apply来实现es6里面的...运算符?)


// `b` onto `a`:

a.push.apply( a, b );

a; // [1,2,3,4,5,6,7,8,9,"foo","bar","baz","bam","bun","fun"]


// or `a` into `b`:

b.unshift.apply( b, a );


b; // [1,2,3,4,5,6,7,8,9,"foo","bar","baz","bam","bun","fun"]


繁花不似锦
浏览 602回答 3
3回答

UYOU

首先你要知道apply是干啥的,apply会改变方法的this指向为第一个参数,第二个参数是个数组
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript