Understand context given statement

Asked

Viewed 120 times

1

I have this particular function statement:

datasetCSR = this.execECM(function () {
    var co = this.DatasetFactory.createConstraint("ibv", instance, instance, this.ConstraintType.MUST);
    return this.DatasetFactory.getDataset("csr", null, [co], null);
});

execECM is a function.

I would like to know the theory and context of this kind of function statement.

When datasetCSR is executed it automatically executes exeECM?

  • 6

    Is this what you want to know? http://answall.com/q/9936/101

  • 1

    I’m not quite sure what you ask in the question. Now this.execECM is a function. What do you want to know? about this.execECM or the function that is passed to you as an argument? You can explain your question better?

  • I would like to understand the logic of this function creation mode. execECM is a function yes. What I don’t understand is what is happening. datasetCSR is a function that when executed it calls the exeECM function?

1 answer

1


datasetCSR is a variable that when declared executes and receives the return value of the method execECM.

Considering the definition of the object 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 method execECM receives a function such as callback to use at some point in the scope of your 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.