-
-
Save arsonus/3b93b8d06d6939012e9b234f8487007e 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