javascript - Covering the case when no function is passed to another function -


i have function can passed complete function. don't want invoke complete if not null do

function queryjs(sql, success, error, complete) {  ... ... if (complete !== null) complete() ... ... 

when invoke function 3 params such as:

queryjs("select blah table", mysuccess, myerror)  

i get:

typeerror: complete not function 

what doing wrong?

and best way cover case of no complete function passed.

thanks

an empty argument undefined. should check if complete function:

if (typeof complete === "function") {   complete(); } 

to throw error invalid complete values check either undefined or arguments array length:

if (typeof complete !== "undefined") {   complete(); }  if (arguments.length >= 4) {   complete(); } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -