0

The question title might be a misleading and this might be more of a generic javascript question, but anyways, I noticed in the example given in http://backbonejs.org/#Collection-reset

var accounts = new Backbone.Collection;
accounts.reset(<%= @accounts.to_json %>);

that new Backbone.Collection is called without parentheses at the end.

//Is there any difference?
var accounts = new Backbone.Collection;
var accounts = new Backbone.Collection();

What's the difference?

fortuneRice
  • 4,214
  • 11
  • 43
  • 58
  • 3
    possible duplicate of [new MyObject(); vs new MyObject;](http://stackoverflow.com/questions/3034941/new-myobject-vs-new-myobject) – nikoshr Oct 03 '13 at 11:03
  • 1
    For quick reference, there is no difference : new Backbone.Collection === new Backbone.Collection(); – Praveen Vijayan Oct 03 '13 at 11:09

1 Answers1

0

As stated by nikoshr, this is a duplicate of Can we omit parentheses when creating an object using the "new" operator?

The answer, as given there, is:

no, there is no difference.

If no arguments are required for your constructor, it is simply a shorthand convenience in Javascript to not have to specify that. However, some consider it bad practice, including Douglas Crockford.

Community
  • 1
  • 1
dthree
  • 19,847
  • 14
  • 77
  • 106