我有一个库,其中添加了以下数组类型 -
Array.prototype.top = function() {
return (this.length > 0) ? this[this.length-1] : null;
}
它似乎适用于非数组对象 - 例如,
for (key in myrecordset) {
alert(key); // will iterate and alert "top";
}
在调试器控制台中:
> myrecordset.length
< undefined
> typeof myrecordset
< 'object'
> myrecordset instanceof(Array)
< false
> myrecordset['top']
< f() {
return (this.length ...
}
那么,这是什么情况?该对象不是 JavaScript 数组(即,没有长度,不是实例,...),但 Array.prototype.top 似乎已应用?
注意:此外,尝试遵循原型链我得到
> myrecordset.constructor()
< {}
[[ Prototype ]]: Object