Last active
December 14, 2015 05:49
-
-
Save Havvy/5037770 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
// These are also the same function as below, with slightly different syntax. | |
function new (constructor, args) { | |
var binding = Object.create(constructor.prototype); | |
var retval = constructor.apply(binding, args); | |
if (retval === null || typeof retval !== 'object') { | |
return binding; | |
} | |
return retval; | |
} |
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 (constructor, args) { | |
var binding = Object.create(constructor.prototype); | |
var retval = constructor.apply(binding, args); | |
if (retval === null || typeof retval !== 'object') { | |
return binding; | |
} else { | |
return retval; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given a constructor Foo,
new Foo(a, b, c)
would be the same asnew(Foo, [a, b, c])
.I say would be, because
new
is a reserved word, so the function doesn't actually compile.