-
-
Save RacingTadpole/59b22af8e2b5462ddb25 to your computer and use it in GitHub Desktop.
This file contains 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
// Crockford's new_constructor | |
// Act III: Function the Ultimate | |
// yuiblog.com/crockford | |
function new_constructor(extend, initializer, methods) { | |
var func, prototype = Object.create(extend && | |
extend.prototype); | |
if (methods) { | |
methods.keys().forEach(function (key) { | |
prototype[key] = methods[key]; | |
}); | |
} | |
func = function () { | |
var that = Object.create(prototype); | |
if (typeof initializer === 'function') { | |
initializer.apply(that, arguments); | |
} | |
return that; | |
}; | |
func.prototype= prototype; | |
prototype.constructor= func; | |
return func; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment