-
-
Save monolithed/3229123 to your computer and use it in GitHub Desktop.
setPrototypeOf
This file contains 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.setPrototypeOf is not going to happen. Writable __proto__ | |
is a giant pain to implement (must serialize to cycle-check) | |
and it creates all sorts of type-confusion hazards (Brendan Eich). | |
*/ | |
Object.setPrototypeOf = function (object, proto) { | |
var __proto__ = proto; | |
do { | |
if (object === __proto__) | |
throw new Error('Circular prototype chain'); | |
} | |
while (__proto__ = Object.getPrototypeOf(__proto__)); | |
object.__proto__ = proto; | |
return object; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment