javascript - A little JS help here please.. avoiding errors with undefined objects/variables (supression perhaps?) -


i'm annoyed @ js stopping @ simple undefined error..

i have routine need "set" variables based on what's in global scope

targetid = mydata.id; targetid = mydata.targetvalue; 

these objects may or may not set, depending on previous operations...

i error:

typeerror: mydata undefined targetvalue =  mydata.targetvalue; 

and rest of js code stops executing!

annoying..

coming php , as2 , other languages, script never stops on me coz of undefined value..

now know can test "undefined" before setting variable.. in reality have whole bunch of variables set , running condition on "each" bit stupid..

how tell js continue running regardless of undefined vars/objects?

or atleast, how suppress errors specific code (not global) ..

in php, preceding call w/ "@" symbol suppresses warnings or error..

the problem here not value undefined. problem you're trying access property on undefined, throws error (which should do).

i don't know php, can't imagine doesn't throw error when happens.

what prevent following:

mydata = mydata || {};  // assure mydata not undefined. way next call not try retrieve property on undefined. targetid = mydata.id; targetid = mydata.targetvalue; 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -