Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Collection seems chainable in the Chainable API example #669

Open
ravenjam opened this issue Jul 17, 2015 · 0 comments
Open

Collection seems chainable in the Chainable API example #669

ravenjam opened this issue Jul 17, 2015 · 0 comments

Comments

@ravenjam
Copy link

In Chainable API example I saw this:

var collection = new Backbone.Collection([
  { name: 'Tim', age: 5 },
  { name: 'Ida', age: 26 },
  { name: 'Rob', age: 55 }
]);

var filteredNames = collection.chain() // start chain, returns wrapper around collection's models
  .filter(function(item) { return item.get('age') > 10; }) // returns wrapped array excluding Tim
  .map(function(item) { return item.get('name'); }) // returns wrapped array containing remaining names
  .value(); // terminates the chain and returns the resulting array

console.log(filteredNames); // logs: ['Ida', 'Rob']

Therefore I tested to just use the collection without the chain() method. It seems that it worked well. I ran this in the console:

var collection = new Backbone.Collection([
  { name: 'Tim', age: 5 },
  { name: 'Ida', age: 26 },
  { name: 'Rob', age: 55 }
]);

collection
  .filter(function(item) { return item.get('age') > 10; })
  .map(function(item) { return item.get('name'); }) ;

and it returns ['Ida', 'Rob'].

I'm wondering why? It seems that the chain() method is not necessary? Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant