我有以下js代码:
var T = function(){};
var tw = new T();
T.prototype.toString = function(){return "1";};
Object.prototype.findOwnerOfProperty = function(propName){
var currentObject = this;
while(currentObject !== null){
if(currentObject.hasOwnProperty(propName)){
return currentObject;
} else {
currentObject = currentObject.__proto__;
}
}
return "No property found!";
};
console.log(tw.findOwnerOfProperty("toString"));
首先,我使用JavaScript引擎V8 3.17.6.15在Chrome 27.0.1453.110上运行它。输出是:
Object {toString: function, findOwnerOfProperty: function}
然后我使用JavaScript引擎V8 3.30.33.16在Chrome 40.0.2214.111上运行它。输出是:
T {toString: function, findOwnerOfProperty: function}
有谁知道为什么输出不同?