Created
March 24, 2019 06:19
-
-
Save gokulkrishh/e4c0f65011f409fa06c99a5b3572f31e to your computer and use it in GitHub Desktop.
A simple polyfil for Object.create method.
This file contains hidden or 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
// without 2nd argument support | |
if (typeof Object.create !== 'function') { | |
Object.create = function(o, props) { | |
function F() {} | |
F.prototype = o; | |
return new F(); | |
} | |
} | |
// with 2nd argument support | |
if (typeof Object.create !== 'function') { | |
Object.create = function(o, props) { | |
function F() {} | |
F.prototype = o; | |
var result = new F(); | |
if (typeof props === 'object') { | |
for (prop in props) { | |
if (props.hasOwnPropertyOf(prop)) result[prop] = props[prop].value; | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment