In Javascript, is there any difference between calling new foo()
and simply foo()
?
In other languages, the new keyword is required, but in Javascript, since Objects are created via functions as constructors, the new
keyword should be neither necessary nor beneficial in any way.
For instance:
function foo(){
return { a:2, b:3, hello: 'world' }
}
If I call new foo()
, it returns the same result as foo()
.
I know the newest ECMAscript spec has classes which would maybe need the new keyword, but I really only care about function object constructors.