How can you pass parameters to a function when using .call() in Javascript?
When I pass parameters they are always undefined in the callback function
EDIT (an example):
I will have an options object in my plugin:
var options = {
errorCallback : function( errors ) {}
}
I will call this from my plugin like this:
var errors = "Test error list";
configs.errorCallback.call(errors);
I will initialise my plugin like this
$('#plugin-element').myPlugin(
{
'errorCallback' : function errorrCallbackFunction( errors ) {
console.log(errors) //always undefined
}
}
The first argument of call is the ‘this’ of the function. If you want to pass the variable as argument start from the second one.
Here is the documentation: Function.prototype.call()