javascript - is this callback structured correctly? -


i want save sections, made updates questions ids saved sections, save questions, , if successful fire function nextpage redirects page. i'm trying confirm correct. seems act funny if don't have anonymous function wrapped around saveallquestions.

saveallsections(function () {saveallquestions(nextpage)}); 

update:

on success of saveallsections following:

if (typeof(callback) == 'function')                callback();  

on success of saveallquestions following:

            if (questionvaluestosave.length>0) {                 saveallquestionvalues(questionvaluestosave, callback);             }             else {                  // once done hide ajax saving modal                 hidemodal();                 if (typeof(callback) == 'function')                     callback();             }  

on success of saveallquestionvalues (assuming there some) following:

                    if (typeof(callback) == 'function')                         callback(); 

yes correct syntax callback, though hard know sure without seeing more code.

the following code

saveallsections(saveallquestions(nextpage)); 

would fail because saveallquestions(nextpage) syntax execute function, rather define it. execute , pass result saveallsections, try use callback. since not function, , not function want pass strange behavior, error.

wrapping in anonymous function means you're passing function saveallsections, not execute until called outer function or callback.

update:

looks saveallquestions async based on description, executing not work correctly. anonymous function wrapper acceptable solution if need pass param.

if didn't, use

saveallsections(saveallquestions) 

Comments

Popular posts from this blog

Need help in packaging app using TideSDK on Windows -

java - Why does my date parsing return a weird date? -

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -