About Pi Downloads Documentation Plugins Developer Forum Issues

Function.curry

Summary

Returns a generic curried version of specified function.

Syntax

function.curry(scope,arguments...)

Example

>>> var add = function(n1,n2){
>>> 	return n1+n2;
>>> }
>>> add(1,2);
3
>>> var a = add.curry(window,1);
>>> a(2);
3
>>> a(5);
6
>>> add.curry(window,1)

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" ) );

See Also