Created
January 27, 2015 03:57
-
-
Save dead-claudia/da1d120e61cb88072716 to your computer and use it in GitHub Desktop.
Object.prototype.__proto__ polyfill for ES6 (if the runtime *doesn't* implement it -- it's technically optional for non-web browsers)
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
/** | |
* By Isiah Meadows. | |
* This code is licensed under CC0 1.0 Universal. You can get a copy of the license at https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt | |
*/ | |
if (!function (F) { | |
return {}.__proto__ === Object.prototype; // Also if it's broken | |
}(function () {}) && Object.getPrototypeOf && Object.setPrototypeOf) { | |
Object.defineProperty(Object.prototype, '__proto__', { | |
'get': function () { | |
return Object.getPrototypeOf(this); | |
}, | |
'set': function (proto) { | |
return Object.setPrototypeOf(this, proto); | |
} | |
}); | |
} |
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
/*By Isiah Meadows. This code is licensed under CC0 1.0 Universal. You can get a copy of the license at https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt*/Object.prototype!=={}.__proto__&&Object.getPrototypeOf&&Object.setPrototypeOf&&Object.defineProperty(Object.prototype,'__proto__',{'set':function(p){return Object.setPrototypeOf(this,p)},'get':function(){return Object.getPrototypeOf(this)}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More performant version: