cf2:js.Function#Prefix

Purpose

Provides a limited form of currying. It can only handle a single level of currying, i.e. it returns a function that concatenates the arguments supplied to it to the end of the arguments supplied to the initial function, and then invokes the prefixed function.

It is especially useful when working with callback functions. The Client Framework 2 makes use of a lot of callback functions and in some situations functions need to be passed additional arguments that are not provided by the callback.

Exported Features

cf2:js.Function#Prefix

Imported Features

n/a

JavaScript

This component provides the following method:

v_prefix(...)

Creates a curried function which, when called, will use the supplied value for the this variable.

Parameter Description Type
... A list of arguments that will prefix the arguments supplied to the returned function when the prefixed function is called. any

Example

// Create a function.
function add = function(x, y) {
  return x + y;
}

// Create another function.
var inc = add.v_prefix(1);

// Use the new function.
inc(4);
>>5

Related topics