Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top