0

I am trying to create a plugin with callbacks, however I can't pass a parameter to the callback function.

I am calling the callback within the plugin as follows:

console.log(response.data);
base.options['onFinished'].call(response.data);

As expected response.data is propogated with the correct data, however on the other end where I defined the callback:

$ele.app({
   onFinished: function(data) {
      console.log(data);
   }
);

It is being called, however data is "undefined".

2 Answers 2

1
options.onFinished.call(this,response.data);
Sign up to request clarification or add additional context in comments.

Comments

0

The first argument to call should be the value used for this in the called function, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call

base.options['onFinished'].call(this, response.data);

Note you can choose what you want the context set to. Typically you would want it to be the element that triggered the event that is being handled. The sample assumes that is also the the context of the currently executing plugin function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.