Skip to content

Instantly share code, notes, and snippets.

@adriancmiranda
Forked from roboticstone/object.create.js
Last active January 9, 2016 13:31
Show Gist options
  • Save adriancmiranda/c1eea5364bea552c171e to your computer and use it in GitHub Desktop.
Save adriancmiranda/c1eea5364bea552c171e 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) {
var instance, prop;
// Create new object whose prototype is o
function F() {}
F.prototype = o;
instance = 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.
instance[prop] = props[prop].value;
}
}
}
// Return new object
return instance;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment