datasetCSR
is a variable that when declared executes and receives the return value of the execECM
method.
Given the object definition as:
var obj = {
execECM: function ( callback )
{
// será passado como argumento para esse método
// uma função como callback
// você poderá invocá-la a qualquer momento dentro do contexto
// de execECM
return callback() + 5;
},
myCustomFunction: function ( value )
{
// declarando datasetCSR e associando seu valor ao valor de retorno
// do método execECM
var
datasetCSR = this.execECM( function () {
return value;
} );
console.log( datasetCSR );
}
};
The execECM
method receives a function such as callback to use at some point in the scope of its declaration.
A callback function, also known as a higher-order function, is a function that is passed to another function (let's call this other function "otherFunction") as a parameter, and the callback function is called (or executed) inside the otherFunction.
Understand JavaScript Callback Functions and Use Them
Using the previously declared object, we will have:
obj.myCustomFunction( 10 ); // 15
obj.myCustomFunction( 1 ); // 6
obj.execECM( 10 ) // Uncaught TypeError: callback is not a function(…)
var calls = function ()
{
return 100;
};
obj.execECM( calls ); // 105