Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Overriding issue

Tags:

javascript

I struck up in a Javascript method overriding problem for a while. the problem is i got onclick event handler on one of my controls and i need to to do inject some method before the event handler triggers the actual method.

assume DGrid.Headerclik is actuall assigned to onclick event.

And this is what i did

  DGrid.Headerclik  = handleinLocal;

so whenever user clicks the grid now the control comes to handleinLocal method. here i have to do some processing and then call the base Headerclik().

  function handleinLocal(){
      // here i need to call the DGrid.Headerclik() method (base)
  }

but this is not working as expected. on calling the DGrid.Headerclik() within the handleinLocal() recursively calls the handleinLocal() method. But i need to call the base method...

is there a way to achieve theis in JavaScript??

like image 628
RameshVel Avatar asked Sep 10 '26 08:09

RameshVel


1 Answers

You should store the previous handler in a (closure) variable:

(function() {
   var oldHandler = DGrid.Headerclik;

   DGrid.Headerclik = handleInLocal;

   function handleInLocal() {
      // ...
      oldHandler();
      // ...
   }
})();
like image 65
Philippe Leybaert Avatar answered Sep 11 '26 22:09

Philippe Leybaert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!