Created
November 17, 2016 02:59
-
-
Save newswim/31cb0da08bb48dbc4a89149ef4606c22 to your computer and use it in GitHub Desktop.
Object.create simple polyfill
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
/** | |
* @param {object} o - this object will be the Prototype of the newly created object. | |
*/ | |
if (!Object.create) { | |
Object.create = function (o) { | |
if (arguments.length > 1) { | |
throw new Error('Object.create implementation only accepts the first parameter.'); | |
} | |
function F() {} | |
F.prototype = o; | |
return new F(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment