jashkenas/coffee-script — pull request #2597 by gampleman (2012-10-26 20:32:36+00:00)
Title: Partial function application

This is my attempt at implementing partial application as proposed in #2585.

To summarize:

~~~coffeescript
add = (a,b) -> a + b
add_3 = add 3, ...
7 == add_3 4

class A
constructor: (@value = 0) ->
increment_by: (num) -> @value += num
increment: @increment_by(1, ...)

a = new A
a.increment()
a.value == 1
~~~

~~~javascript

var A, a, add, add_3;

add = function(a, b) {
return a + b;
};

add_3 = (function() { return add.apply(null, [3].concat(__slice.call(arguments))); });

7 === add_3(4);

A = (function() {

function A(value) {
this.value = value != null ? value : 0;
}

A.prototype.increment_by = function(val) {
return this.value += val;
};

A.prototype.increment = (function() { return this.increment_by.apply(this, [1].concat(__slice.call(arguments))); });

return A;

})();
a = new A;
a.increment();

a.value === 1;
~~~