Skip to content

Instantly share code, notes, and snippets.

@CodeDmitry
Last active May 2, 2019 12:26
Show Gist options
  • Select an option

  • Save CodeDmitry/1ae6d19b4877ba9fc63a3139e52e3d9b to your computer and use it in GitHub Desktop.

Select an option

Save CodeDmitry/1ae6d19b4877ba9fc63a3139e52e3d9b to your computer and use it in GitHub Desktop.
object_whose
(function() {
// | finds the owner of the specified property based on prototype chain.
function object_whose(propName) {
if (this.hasOwnProperty(propName)) return this;
var p = this.__proto__;
while (p) {
p = p.__proto__;
if (p.hasOwnProperty(propName)) {
return p;
}
}
return null;
}
Object.prototype.whose = object_whose;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment