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
Post a Comment