javascript - Create event listener that will automatically execute callbacks after first fire -


i create 1 time event listener execute callbacks after event fired first time.

main.js: (loaded first thing)     $(document).one('plugins_loaded', displaymenu);  plugins.js: (loaded time after main.js)     $(document).trigger('plugins_loaded');  checkout.js: (loaded asynchronously or after main.js)     $(document).one('plugins_loaded', displaycart); 

i want displaycart execute immediately, if plugins_loaded event triggered before, , if not, displaycart should called after displaymenu, when plugins_loaded event fires.

you looking for

store either in global variable, best in namespace of application object. need initialise once, can add callbacks whereever , whenever want, , trigger them somewhen later.

you cannot use custom event fired on $(document), past events not observable.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -