Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created August 18, 2014 04:26
Show Gist options
  • Save jonathantneal/8f171a98028d6bbd5625 to your computer and use it in GitHub Desktop.
Save jonathantneal/8f171a98028d6bbd5625 to your computer and use it in GitHub Desktop.
Object.create: useless extras edition
// Object.create
Object.create = function create(prototype, properties) {
var
isFunction = typeof prototype === 'function',
name = isFunction && Function.prototype.toString.call(prototype).match(/^function\s+(\w*)/)[1] || 'Object',
object;
if (!isFunction && typeof prototype !== 'object') {
throw new Error('Object prototype may only be an Object or null');
}
object = new Function('e', 'function ' + name + '(e){}' + name + '.prototype=e;return new ' + name)(prototype);
if (properties) {
Object.defineProperties(object, properties);
}
return object;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment