.extend()
Extends the base Collection class by adding/overwriting methods.
extend(extensions)
Parameter
Description
extensions
An object with the methods
Returns
Description
A modified version of the base Collection class with the new methods
const ExtendedPosts = Posts.extend({
// Add new methods
chunk(count) {
const data = this.getAll();
const newArr = [];
for (var i = 0; i < data.length; i+=count)
newArr[i/count] = data.slice(i, i+count);
return newArr;
},
// Overwrite existing methods
create: () => {
// Whatever you wanna do here.
}
});
ExtendedPosts.createBulk([
{ content: '1' },
{ content: '2' },
{ content: '3' },
{ content: '4' }
]);
ExtendedPosts.chunk(2); // [ [{content:'1'},{content:'2'}], [{content:'3'},{content:'4'}] ]
Last updated
Was this helpful?