JavaScript scope discrepancy between Chrome and Firefox -
i wrote jquery plugin force numerical values in input fields, , works fine in chrome , safari not in firefox. have posted piece of script below, , in firefox fails on first line, error referenceerror: setdefault not defined
. why wouldn't line work in firefox?
isdollar = setdefault(options.isdollar, isdollar); isreal = setdefault(options.isreal, isreal); allowdecimal = setdefault(options.allowdecimal, allowdecimal); allownegative = setdefault(options.allownegative, allownegative); maxdigits = setdefault(options.maxdigits, maxdigits); function setdefault(myvar, defaultval){ if(typeof myvar === "undefined") myvar = defaultval; return myvar; }
seems firefox has more strict interpretation of ecma standards. left out of code snippet whole thing inside of if
block. apparently, in case, javascript executed in firefox not able call setdefault
before declared. interesting code work in other browsers explode in firefox. lesson learned.
Comments
Post a Comment