Skip to content

Instantly share code, notes, and snippets.

@gokulkrishh
Created March 24, 2019 06:19
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 gokulkrishh/e4c0f65011f409fa06c99a5b3572f31e to your computer and use it in GitHub Desktop.
Save gokulkrishh/e4c0f65011f409fa06c99a5b3572f31e to your computer and use it in GitHub Desktop.
A simple polyfil for Object.create method.
// 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