1 | # ampersand-collection-underscore-mixin
|
2 |
|
3 | A mixin for extending ampersand-collection with underscore methods.
|
4 |
|
5 | If you're using an [ampersand-rest-collection](http://ampersandjs.com/docs/#ampersand-rest-collection) this is already mixed in for you.
|
6 |
|
7 | Out of the box, ampersand-collections proxy the [ES5 iteration methods already](http://ampersandjs.com/docs/#ampersand-collection-proxied-es5-array-methods-9) so you don't _have_ to use this mixin, but if you want all the underscore methods, or better browser support, you can use this.
|
8 |
|
9 | ## install
|
10 |
|
11 | ```
|
12 | npm install ampersand-collection-underscore-mixin
|
13 | ```
|
14 |
|
15 | ## example
|
16 |
|
17 | ```javascript
|
18 | var Collection = require('ampersand-collection');
|
19 | var underscoreMixin = require('ampersand-collection-underscore-mixin');
|
20 |
|
21 |
|
22 | module.exports = Collection.extend(underscoreMixin, {
|
23 | sampleMethod: function () {
|
24 | // now we've got underscore methods
|
25 | // we can call that are applied to models
|
26 | // in the collection.
|
27 | this.filter( ... );
|
28 | this.some( ... );
|
29 | this.each( ... )
|
30 | }
|
31 | });
|
32 | ```
|
33 |
|
34 | ## credits
|
35 |
|
36 | All credit for underscore and this approach in backbone goes to Jeremy Ashkenas and the rest of the Backbone and Underscore authors.
|
37 |
|
38 | If you like this follow [@HenrikJoreteg](http://twitter.com/henrikjoreteg) on twitter.
|
39 |
|
40 | ## license
|
41 |
|
42 | MIT
|
43 |
|