Created
June 29, 2015 11:33
-
-
Save IUnknown68/73a0f033fceba19363a2 to your computer and use it in GitHub Desktop.
Collection function calling each item (Like `setModified()`, `getModified()`).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// 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