Skip to content

Instantly share code, notes, and snippets.

@xat
Created November 7, 2014 22:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xat/a9fae4828b6defd013ea to your computer and use it in GitHub Desktop.
Save xat/a9fae4828b6defd013ea to your computer and use it in GitHub Desktop.
last.js
var last = function(fn, l) {
return function() {
var args = Array.prototype.slice.call(arguments);
args.push(l);
return l = fn.apply(null, args);
};
};
@xat
Copy link
Author

xat commented Nov 7, 2014

// example
var exp = last(function(l) { return l*2; }, 1);

exp(); // 2
exp(); // 4
exp(); // 8
exp(); // 16
//... and so on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment