pi.util.Curry
Summary
Returns a generic curried version of specified function.
Syntax
pi.util.Curry(function,scope,arguments ...)
Usage Example
>>> var add = function(n1,n2){
>>> return n1+n2;
>>> }
>>> add(1,2);
3
>>> var a = pi.util.Curry(add,window,1);
>>> a(2);
3
>>> a(3)
4
>>> a(-1)
0
Examples
Example #1: Write a function that changes fore color of the given element.And add that function to two different buttons onclick event.
Source files of the above example:
../../examples/curry.html
<button id="button1">Foo</button>
<button id="button2">Bar</button>
../../examples/curry.js
function paint(_color, _event){
this.style.backgroundColor = _color;
this.innerHTML = _event.clientX + 'x' + _event.clientY;
}
var button1=pi.get("button1"), button2=pi.get("button2");
pi.util.AddEvent( button1, "click", paint.curry( button1, "red" ) );
pi.util.AddEvent( button2, "click", paint.curry( button2, "green" ) );