Skip to content

Instantly share code, notes, and snippets.

@roboticstone
Forked from lavoiesl/object.create.js
Last active February 24, 2020 13:23
Show Gist options
  • Save roboticstone/bf537252607286aa8ef6 to your computer and use it in GitHub Desktop.
Save roboticstone/bf537252607286aa8ef6 to your computer and use it in GitHub Desktop.
// Object.create Partial Polyfill
// Support for second parameter is non-standard
if (typeof Object.create !== 'function') {
Object.create = function(o, props) {
// Create new object whose prototype is o
function F() {}
F.prototype = o;
result = new F();
// Copy properties of second parameter into new object
if (typeof(props) === "object") {
for (prop in props) {
if (props.hasOwnProperty((prop))) {
// Even though we don't support all of the functionality that the second
// parameter would normally have, we respect the format for the object
// passed as that second parameter its specification.
result[prop] = props[prop].value;
}
}
}
// Return new object
return result;
};
}
@Mouvedia
Copy link

Try to pass null as the second argument. You need to throw in that case.

@nicholas-ross
Copy link

You're missing a var for the result and prop so you are creating global variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment