Skip to content

Instantly share code, notes, and snippets.

@IUnknown68
Created June 29, 2015 11:33
Show Gist options
  • Save IUnknown68/73a0f033fceba19363a2 to your computer and use it in GitHub Desktop.
Save IUnknown68/73a0f033fceba19363a2 to your computer and use it in GitHub Desktop.
Collection function calling each item (Like `setModified()`, `getModified()`).
//------------------------------------------------------------------------------
// Create a function `collection.fnName`.
// The function applies `_.lodashFn` on `collection` and calls `fnName` on
// each item.
// @param collection Any collection lodash can process
// @param fnName Name of function generated.
// @param lodashFn Name of the lodash collection function to apply.
// Defaults to 'each'.
function createCollectionProxyFn(collection, fnName, lodashFn) {
lodashFn = lodashFn || 'each';
collection[fnName] = function() {
var args = arguments;
return _[lodashFn](collection, function(item) {
return item[fnName].apply(item, args);
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment