cf2:js.Function#Bind

Purpose

Callback functions used by the Client Framework 2 may require decorating. This component can be applied in the following cases. If the selected function is a method on an object, then it will need a value of this to be passed to it. The cf2:js.Function#Bind component handles this situation by allowing a value for the this variable. If the function requires additional arguments that are not provided by the callback, then they need to be supplied before they are registered. This is handled in the same way as the v_prefix function. See cf2:js.Function#Prefix for details.

Exported Features

cf2:js.Function#Bind

Imported Features

n/a

JavaScript

This component provides the following method:

v_bind(thisArg, ...)

Creates a function which, when called, will call the current function with the supplied value of the this variable and with the specified prefix arguments.

Parameter Description Type
thisArg The value of the this variable. If thisArg is null, then the global object will be used as the value of this. Object
... An optional list of arguments that will prefix the arguments supplied to the returned function when the bound function is called. any

Example

// Create a class object.
function Class(v) {
  this.property = v;
}
Class.prototype.method = function(x, y) {
  return this.property + x + y;
};
var object = new Class(12);

// Call the method function directly, without supplying a this object
// so it defaults to the global object.
Class.prototype.method(6, 7);
>>NaN

// Create a function that will invoke the method on the specified
// object.
var f = Class.prototype.method.v_bind(object, 6);
f(7);
>>25

Related topics