Module: cbo

Callback object tool

Contents

  1. Definition
  2. Call tool

  3. Build tool

Definition

callback object

A callback object is an array object defined as :

a. [ thisObj, methodName, argArray ]
b. [ thisObj, method, argArray ]
c. [ null, method, argArray ]

Properties:
Name Type Attributes Description
thisObj object

The this objecct

methodName string

A function name of thisObj

method function

A function

argArray Array <optional>

An arguments array for calling the method

Example
var cbo= require("cbo");

cbo.call(...);

Methods

(inner) call(cbo, argArrayExtraopt, insertBeforeopt)

call a cbo

Parameters:
Name Type Attributes Description
cbo cbo

a cbo object

argArrayExtra Array <optional>

extra arguments array

insertBefore bool <optional>

flag to insert argArrayExtra before original argArray of cbo

Returns:

according to the cbo

(inner) combine(cbo, argArrayExtraopt, insertBeforeopt)

combine arguments into cbo

Parameters:
Name Type Attributes Description
cbo cbo

a cbo object

argArrayExtra Array <optional>

extra arguments array

insertBefore bool <optional>

flag to insert argArrayExtra before original argArray of cbo

Returns:

a new cbo

(inner) toCallback(cbo, reserveopt)

create a normal callback function

Parameters:
Name Type Attributes Description
cbo cbo

a cbo object

reserve number <optional>

the count of reserved original prefix arguments

Returns:

a callback function

Example
function f(a1,a2,a3,a4){
    console.log([a1,a2,a3,a4]);
}

var cboTest= [null,f,['aa']];
var cb1= cbo.toCallback(cboTest);
cb1();	//aa
cb1('bb');	//bb,aa
cb1('bb','cc')	//bb,cc,aa
var cb2= cbo.toCallback(cboTest,0);
cb2();	//aa
cb2('bb');	//aa
var cb3= cbo.toCallback(cboTest,1);
cb3();	//undefined,aa
cb3('bb');	//bb,aa
cb3('bb','cc');	//bb,aa