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
  • 138,174
  • 23
  • 272
  • 326
James
  • 109,676
  • 31
  • 162
  • 175