jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.09k stars 5.38k forks source link

Doc inconsistency in Collection constructor #2966

Closed jfschwarz closed 10 years ago

jfschwarz commented 10 years ago

The docs (http://backbonejs.org/#Collection-constructor) indicate that the models array is an optional parameter for the Backbone.Collection constructor method:

new Backbone.Collection([models], [options])

In fact, it can only be omitted when no options are passed in. Sketch for a simple test case, demonstrating the deviation from the docs:

test("new empty collection with options", function() {
    var col = new Backbone.Collection({model: Backbone.Model});
    equal(col.length, 0);
});
jashkenas commented 10 years ago

That's not an inconsistency. JavaScript uses positional arguments — you're trying to pass in the options as the models. Sans type sniffing, almost any function that accepts more than one argument will work the same.