1

Possible Duplicate:
new MyObject(); vs new MyObject;

I keep seeing code like this one:

var obj = new Constructor; // no parantheses

//here's an example i've seen for the `node-lazy` library
//url: http://www.catonmat.net/blog/nodejs-modules-lazy/
var lazy = new Lazy;

e.g. when instantiating an object by calling a constructor, some people don't use parantheses. This still works. Can you explain to my why? Does it have advantages? Is this a good practice? Do you need some special code in the constructor function for this to work?

Community
  • 1
  • 1
alexandru.topliceanu
  • 2,364
  • 2
  • 27
  • 38

1 Answers1

0

No advantage (unless you count two characters less an advantage). That's just the way JavaScript is (PHP has this "feature" too). It's just shorter. But if you want to pass arguments to the constructor you will have to include "( and )".

Jan Hančič
  • 53,269
  • 16
  • 95
  • 99