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?
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.