Created
August 18, 2014 04:26
-
-
Save jonathantneal/8f171a98028d6bbd5625 to your computer and use it in GitHub Desktop.
Object.create: useless extras edition
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
// 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