【发布时间】:2011-09-30 00:08:24
【问题描述】:
我希望能够用方法扩充Array.prototype,然后在任何数组上调用它们:
>>> [1, 2, 3].customMethod();
但似乎数组没有原型...?
>>> [1, 2, 3].prototype
undefined
我错过了什么吗?
看来我的实际问题出在其他地方:调用[1, 2, 3].customMethod() 有效,但调用someDomElement.childNodes.customMethod() 失败。 childNodes 不是真正的数组吗?
childNodes.filter is not a function
【问题讨论】:
-
push/pop 等怎么样?您是在实例上分配原型,而不是在 Array 类型上。
标签: javascript arrays methods prototypal-inheritance