简体   繁体   中英

Pure JavaScript equivalent of jQuery's $( document ).on( 'pjax:complete', () => { … } );} );

I have legacy code like this below. My goal replace jQuery in the project to pure JS .

...
$( document ).on( 'pjax:complete', () => {
    executeSomething();
} );
...

executeSomething() - accesses to API, executes some calculations based on it and renders the result on the active tab.

I wrapped this function to IIFE and it works

...
( function() {
    executeSomething();
})();
...

Question : Is this a similar implementation?

Dependencies

  • jQuery v3.2.0
document.addEventListener('pjax:complete', () => {
  executeSomething();
});

An IIFE executes immediately. An event listener triggers the function only when the event occurs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM