0

Possible Duplicate:
new MyObject(); vs new MyObject;
What is the difference between new Object and new Object() in JavaScript

What is the difference between,

new ClassName;

and

new ClassName();

?

Do they have the same result?

Community
  • 1
  • 1

1 Answers1

10

There is no difference. Use the latter if you want to pass arguments.

The parentheses are also required in chaining:

new ClassName().method();

Creates new ClassName object and calls method on it.

new ClassName.method();

Tries to construct ClassName.method object

See the relevant section in spec

Esailija
  • 134,577
  • 23
  • 263
  • 318
James
  • 106,638
  • 30
  • 159
  • 173