Last active
May 2, 2019 12:26
-
-
Save CodeDmitry/1ae6d19b4877ba9fc63a3139e52e3d9b to your computer and use it in GitHub Desktop.
object_whose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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