Created
January 6, 2017 14:18
-
-
Save wizardnet972/f5a3ca4f222c21308ef4cbf89a5f06c3 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
function new(func, arguments) { | |
// Create a new object that inherits from the constructor's prototype. | |
// func is a constructor function. | |
// arguments is an array of arguments that | |
// are used to invoke the constructor. | |
var that = Object.create(func.prototype), | |
// Invoke the constructor, binding –this- to the new object. | |
other = func.apply(that, arguments); | |
// If its return value is not an object, substitute the new object. | |
return (typeof other === 'object' && other) || that; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment