Skip to content

Instantly share code, notes, and snippets.

@fonzerelly
Last active December 30, 2015 08:19
Show Gist options
  • Save fonzerelly/7801729 to your computer and use it in GitHub Desktop.
Save fonzerelly/7801729 to your computer and use it in GitHub Desktop.
solution: a closure, that cuts of all surplus parameters
_.mixin(
{
"preserveCallersFirstNParams" : function (func, n) {
n = n || 0;
return function () {
return func.apply(this, Array.prototype.slice.call(arguments, 0, n));
};
}
);
var getNumberOfPages = _.preserveCallersFirstNParams(
_.partialRight(
_.result,
"numberOfPages"
),
1
);
_.map(books, getNumberOfPages);
//32, 36, 32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment