Skip to content

Instantly share code, notes, and snippets.

@jimthedev
Created August 5, 2014 21:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jimthedev/075681f56450b5e684f4 to your computer and use it in GitHub Desktop.
Save jimthedev/075681f56450b5e684f4 to your computer and use it in GitHub Desktop.
genericCollectionFactory.js
.factory('genericCollectionFactory',function(){
function Collection() {
var _items = [];
function get () {
return _items;
}
function add (item) {
_items.push(item);
}
function empty () {
// _items = []; // BEWARE!
_items.length = 0;
}
return {
get: get,
add: add,
empty: empty
};
}
return {
create: function () {
return new Collection();
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment