Skip to content

Instantly share code, notes, and snippets.

@wizardnet972
Created January 6, 2017 14:18
Show Gist options
  • Save wizardnet972/f5a3ca4f222c21308ef4cbf89a5f06c3 to your computer and use it in GitHub Desktop.
Save wizardnet972/f5a3ca4f222c21308ef4cbf89a5f06c3 to your computer and use it in GitHub Desktop.
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