In normal cases, new should be used when creating objects from the constructor function and avoided when making any other function call. When using new for function 1) a new object is created; 2) the function is called with the this value associated with this new object, and 3) the value returned by the function (default) is the object created in the first step.
However, in your case, you are returning a completely new object from the "constructor" (different from the object in 1) above), which means that there is no practical difference. The this value will still differ inside the function, but both of them will return false :
new Foo() instanceof Foo; Foo() instanceof Foo;
To illustrate this difference, add the following to Foo :
alert(this instanceof Foo)
When called with new this warns true ; if called without it, false .
Also, it makes no sense to assign a Foo.prototype object because you will never create instances of Foo that could use it (because, again, you are returning something completely different from Foo ).
If you intend to return a custom object from Foo , you should prefer the version without new ; it makes no sense to create a new instance of Foo if you ignore it and return something completely different one way or another.
source share