javascript - How to call a function that is stored in a set of options from within setTimeout() inside an AJAX callback? -


here's relevant code:

success: [              settimeout(function () {                     ajax.success              }, 250),          //... 

the strange thing can call ajax.success within success: [] option, stops working when wrapped in settimeout().

what think work best assigning ajax.success option function right before code gets executed, i'm not sure how so.

any appreciated, , apologies if duplicate. couldn't find similar.

success callback accepts handler or list of handlers. result of calling settimeout unique id associated timeout. it's not function. want is:

success: [     function() {         settimeout(function () {             dostuff();         }, 250),     },     // ... ] 

if function needs use args, can wrap that:

success: [     function() {         var self = this,             args = arguments;          settimeout(function () {             dostuff.apply(self, args);         }, 250),     },     // ... ] 

note this , arguments keywords. note use of .apply.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -