I have a callback function and would like to pass in parameters. I read you can use Apply but I found it to be overly complex and confusing. Here is my binding function:
function onPlotZoom (event, plot, args ) {
$.each( plot.getAxes(), function( event, axisName, axis) {
options[axisName].min = axis.min;
options[axisName].max = axis.max;
options[axisName].scale = axis.scale;
}
}
$( "#plot" ).bind( "plotzoom", onPlotZoom );
My script also has variables which listen on the document whether shift and ctrl pressed and stored like so:
var isShiftPressed = false;
var isCtrlPressed = false;
How can I pass these 2 variables into the callback onPlotZoom? I have tried the following:
$( "#plot" ).bind( "plotzoom", onPlotZoom( isShiftPressed, isCtrlPressed ) );
function onPlotZoom (event, plot, isShiftPressed, isCtrlPressed ) {
$.each( plot.getAxes(), function( event, axisName, axis) {
if(isShiftPressed) {
//do stuff
}
if(isCtrlPressed) {
// do stuff
}
options[axisName].min = axis.min;
options[axisName].max = axis.max;
options[axisName].scale = axis.scale;
}
}
another method I tried was using args and obtaining the property. But this resulted in a cannot find property 0 error:
$( "#plot" ).bind( "plotzoom", onPlotZoom( isShiftPressed, isCtrlPressed ) );
function onPlotZoom (event, plot, args) {
var isShiftPressed = args[0];
var isCtrlPressed = args[1];
// stuff
}