Skip to content

Instantly share code, notes, and snippets.

@anupj
Created June 29, 2015 11:52
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 anupj/641fda3d43456e0cc263 to your computer and use it in GitHub Desktop.
Save anupj/641fda3d43456e0cc263 to your computer and use it in GitHub Desktop.
Implementation of ES5 Object.getPrototypeOf in terms of __proto__
// Copied from Effective Javascript (by David Herman)
// Item 31: Prefer Object.getPrototypeOf to __proto__
// For JS environments that do not provide the ES5 API, it is easy to implement
// in terms of __proto__
if (typeof Object.getPrototypeOf === "undefined" ) {
Object.getPrototypeOf = function(obj) {
var t = typeof obj;
if (!obj || (t !== "object" && t != "function")) {
throw new TypeError("not an object");
}
return obj.__proto__;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment