This is helpful to check and avoid to override properties in an prototype chain.
Lets create a way to find the owner of a specific property given as an argument the name of the property:
Object.prototype.ownerOfProperty = function(propertyName) {
var currentObject = this;
while(currentObject != nulll){
if (currentObject.hasOwnProperty(propertyName)) {
return currentObject;
}
else {
currentObject = currentObject.__proto__;
}
}
return “No property was found”;
};
So we use this by calling it in an object:
ex. myObject.ownerOfProperty(“toString”); and if it find it then it will access to the myObject prototype as the owner and return the details of the property