Underscore supports partials with _.bind()
, the only downside is that you have to always pass this
. So I wanted to see how hard it would be to create my own version of partial.
This is of course a silly exercise, ECMAScript 5th Edition provides a fun.bind()
method that _.bind()
will use that if you have at least IE 9. I just find always passing the this
parameter ugly and from my understanding of functional programming you shouldn't be using this
in a partial anyways.
##Here is my first attempt.
var partial = function(){ var args = Array.prototype.slice.call(arguments), fn = args.shift(); return function(){ return fn.apply(fn, args.concat(Array.prototype.slice.call(arguments) )); }}