Skip to content

Instantly share code, notes, and snippets.

@eligrey
Created July 24, 2009 16:32
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 eligrey/154398 to your computer and use it in GitHub Desktop.
Save eligrey/154398 to your computer and use it in GitHub Desktop.
if (!Object.getPrototypeOf) {
if (typeof this.__proto__ === "object")
Object.getPrototypeOf = function (obj) {
return obj.__proto__;
};
else {
Object.getPrototypeOf = function (obj) {
var constructor = obj.constructor,
oldConstructor;
if (Object.prototype.hasOwnProperty.call(obj, "constructor")) {
oldConstructor = constructor;
if (!(delete obj.constructor)) // reset constructor
return null; // can't delete obj.constructor, return null
constructor = obj.constructor; // get real constructor
obj.constructor = oldConstructor; // restore constructor
}
return constructor ? constructor.prototype : null; // needed for IE
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment