Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
JS Passing Additional Parameters for Bind Callback

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
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!