Created
June 29, 2015 11:52
-
-
Save anupj/641fda3d43456e0cc263 to your computer and use it in GitHub Desktop.
Implementation of ES5 Object.getPrototypeOf in terms of __proto__
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
// 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