title: Stop executing a javascript function when it is called with another parameters
body: <p>I have following scenario</p>
  
  <pre><code>x=1;
  
  myFunction(x){
    if(x==1){
        ...
    }
    else{
        ...
    }
  
  }
  
  myFunction(x);
  
  x=2;
  myFunction(x);
  </code></pre>
  
  <p>Now what is happening that the function with parameter 1 is overriding function 
  with parameter 2 and executing endlessly. But I wanted to stop the exectution of first function when secondly it is called with another parameter.</p>
  
  <p>My real code-</p>
  
  <pre><code>width=1000;
  onWidthChange(width);
  
  $(window).resize(function(){
      width=$(window).width();
      onWidthChange(width);
  });
  
  function onWidthChange(width){
  
      if(width&gt;660){
          $(window).on("scroll",function(){
              var pos=$(this).scrollTop();
  
              $img=$(".navbar-brand img")[0];
  
              if(pos&gt;=674){
                  nav.addClass("navbar-fixed");
                  $img.src="images/Whole_Logo_custom_1.png";
              }
              else{
                  nav.removeClass("navbar-fixed");
                  $img.src="images/logo-v1_4_c.jpg";
              }
  
          });
      }
  }
  </code></pre>
  
  <p>Now the problem here is that the function <em>onWidthChange</em> is executing with parameter 1000 and rest all calls generated on resize have no effects.</p>