Javascript issue

I have been in the Javascript override method for a while. the problem is that I got the onclick event handler on one of my controls, and I need to make some method before the event handler activates the actual method.

Suppose DGrid.Headerclik is activated for the onclick event.

And here is what I did

  DGrid.Headerclik  = handleinLocal;

therefore, whenever a user clicks on a grid, the control is controlled by the localization 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 does not work as expected. when calling DGrid.Headerclik () inside handleinLocal (), it invokes the handleinLocal () method recursively. But I need to call the base method ...

Is there a way to achieve this in JavaScript ??

+3
4

():

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

   DGrid.Headerclik = handleInLocal;

   function handleInLocal() {
      // ...
      oldHandler();
      // ...
   }
})();
+2

, . , , , , .

var callback = DGrid.Headerclik;
DGrid.Headerclik = handleinLocal;

function handleinLocal()
{
     ...your code...
     callback();  // invoke original handler
}
+2

, click,

var oldOnClick = DGrid.Headerclik || function() {};

DGrid.Headerclik = handleinLocal;

function handleinLocal() {
   // Do what you need to do
   oldOnClick();         
}
+1

, () .. .. , , , DGrid - sepearate, . .

DGrid.Headerclik () uses the 'this' operator to access methods and properties from its scope .. so when calling oldHandler (), it runs inside my local one. not really in the DGrid area. (this statement returns the properties of my page not in the DGrid)

to avoid this, I sent oldHandler back to DGrid.Headerclik and immediately called DGrid.Headerclik ().

var oldHandler = DGrid.Headerclik;   
DGrid.Headerclik = handleInLocal;
function handleInLocal(sColumnIdx){
    FormColumnWidthJSONArray();
    //OldHandler(sColumnIdx)    
     DGrid.Headerclik= OldSCCHandler;
    DGrid.Headerclik(sColumnIdx) // To Call the actual Column Click handler in DGrid;
    DGrid.Headerclik= HandleLocal;
}
0
source

Source: https://habr.com/ru/post/1712667/


All Articles