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
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.