2

Think about the silution

function F(){}; //This is a Constructor function

Who can tell me there is any different between

var myInstance = new F; 

and

var myInstance = new F();

? The new keyword execute followed Function immediately anyway whatever that is following by partheses ?

Rui Zha
  • 71
  • 1
  • 4

2 Answers2

5

There is no difference. From the Mozilla Docs:

new constructor[([arguments])]

The parentheses are in square brackets, that means they are optional.

Otto Allmendinger
  • 27,448
  • 7
  • 68
  • 79
0

There is no practical difference, omitting the paranthesis can be done if no arguments are passed to simplify the grammar.

Note that some validators such as JSLint will report a warning if you leave them out though, as it is considered more consistent to always use the same syntax for invoking constructor functions regardless of arguments.

This similar example would be very bad if you get into this lazy habit:

var one = myFunc;
var two = myFunc();

These are two different variables, one is a function reference and the other is the return value of the function.

David Hellsing
  • 106,495
  • 44
  • 176
  • 212