Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda