【发布时间】:2013-05-01 16:34:59
【问题描述】:
我正在使用一个可以接受多个数组的 API,我在其中使用 apply() 来传递数组,但该数组包含一个原型函数,我似乎无法从单个数组中删除该函数。最终发生的是正在执行的原型函数。
这是原型函数:
if ( !Array.prototype.last ) { Array.prototype.last = function(){ return this[this.length - 1]; }}
例如,当我记录每个数组时,我会在 eventList 数组中看到以下内容:
["name1", "index1", "value1", last: function]
["name2", "index2", "value2", last: function]
["name3", "index3", "value3", last: function]
然后我推送数组:
apiName.push.apply( apiName, eventList );
我尝试array.pop() 删除每个数组上的“last”函数,但无济于事。
原型函数最初是如何出现在数组中的,我如何防止它在 apply() 中被调用?
感谢您的任何见解!
【问题讨论】:
标签: javascript arrays prototype apply