addyosmani / addyosmani/backbone-fundamentals
Collection seems chainable in the Chainable API example
- Vorherrschende Sprache
- Rich Text Format
- Sterne
- 9.2k
- Forks
- 1.4k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
In Chainable API example I saw this:
``` javascript
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:
``` javascript
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!
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.