Last active
December 15, 2015 23:38
-
-
Save WebReflection/5341317 to your computer and use it in GitHub Desktop.
On JS interfaces and a possible `Object.prototype.implements()` method
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
| Object.defineProperty( | |
| Object.prototype, | |
| 'implements', | |
| { | |
| enumerable: false, | |
| configurable: true, | |
| writable: true, | |
| value: function (target) { | |
| return Object.getOwnPropertyNames(target).every(function(p){ | |
| var current = this, | |
| aDescriptor = Object.getOwnPropertyDescriptor(target, p), | |
| bDescriptor; | |
| do { | |
| bDescriptor = Object.getOwnPropertyDescriptor(current, p); | |
| } while(!bDescriptor && ( | |
| current = Object.getPrototypeOf(current) | |
| )); | |
| return bDescriptor != null && ( | |
| bDescriptor.value === aDescriptor.value && | |
| bDescriptor.get === aDescriptor.get && | |
| bDescriptor.set === aDescriptor.set | |
| ); | |
| },this); | |
| } | |
| } | |
| ); |
WebReflection
commented
Apr 8, 2013
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment