Skip to content

Instantly share code, notes, and snippets.

@monolithed
Forked from abozhilov/gist:1339681
Created August 1, 2012 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monolithed/3229123 to your computer and use it in GitHub Desktop.
Save monolithed/3229123 to your computer and use it in GitHub Desktop.
setPrototypeOf
/*
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