var elems = { length: 0, add: function (elem) { Array.prototype.push.call(this, elem); }, gather: function (id) { this.add(document.getElementById(id)); } }; elems.gather("first"); console.log(elems.length == 1 && elems[0].id, "Verify that we have an element in our stash"); elems.gather("second"); console.assert(elems.length == 2 && elems[1].id, "Verify the other insertion");
最后
以上就是复杂蚂蚁最近收集整理的关于使用Array的原型使对象具有length,和数组的内容的全部内容,更多相关使用Array内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复