【发布时间】:2017-04-23 19:58:21
【问题描述】:
我正在查看 var args = [true].concat(Array.prototype.slice.call(arguments));我的理解是它试图将函数的参数添加到数组的末尾。但是我不熟悉语法 [true],在数组中具有 true。它试图达到什么目的。如果存在数组,则添加?如果不存在则做一个数组然后添加?
extend: function extend(/* dest, source1, source2, ...*/) {
var args = [true].concat(Array.prototype.slice.call(arguments));
return copyInto.apply(this, args);
},
【问题讨论】:
-
这会将
true添加到数组的开头。 -
刚开始的数组有一个值为
true的元素 -
它只是一个数组,其中一个元素的值为
true。我猜copyInto函数需要一个布尔值作为它的第一个参数。
标签: javascript