In short:
The new statement creates an instance of the object with a new one, and therefore it runs immediately after the declaration.
Not so short
xyz= function(){};
Puts a link to an anonymous function in xyz and points to a function.
xyz= new function(){};
Puts a link to a newly created instance of an anonymous constructor function, so it will point to an object. Try typeof new function(){} and you will get an object.
When the new function(){alert('foo');} code is executed, the following events occur:
- A new object is created.
- The constructor function is called with the specified arguments and is associated with the newly created object. If no argument list is specified, function () is called without arguments.
- The object returned by the constructor function becomes the result of an entire new expression. If the constructor function does not explicitly return an object, the object created in step 1 is used instead.
source share