In Actionscript 3 what is the best way to test if a string is a property of an object -


i test see if string key in object asking:

var foo:object = {bar:"bar", bah:["bah","bah1"]}; var str:string = "boo"; if(foo[str]) // 

but if str == "constructor" - because foo["constructor"] returns true no matter what.

what best way test if string key of object - , not return true constructor?

some examples:

var foo:object = {bar:"bar", bah:["bah","bah1"]}; trace('foo["bar"]: ' + foo["bar"]); trace('foo["bah"]: ' + foo["bah"]); trace('foo["constructor"]: ' + foo["constructor"]); trace('foo["bar"] == true: ' + (foo["bar"] == true)); trace('foo["bah"] == true: ' + (foo["bah"] == true)); trace('foo["constructor"] == true: ' + (foo["constructor"] == true)); if(foo["bar"]){     trace("foo:bar"); } if(foo["bah"]){     trace("foo:bah"); } if(foo["constructor"]){     trace("foo:constructor"); } trace('"constructor" in foo: ' +  ("constructor" in foo)); 

traces:

/* foo["bar"]: bar foo["bah"]: bah,bah1 foo["constructor"]: [class object] foo["bar"] == true: false foo["bah"] == true: false foo["constructor"] == true: false foo:bar foo:bah foo:constructor "constructor" in foo: true */ 

if it's concrete class implementation, should able away hasownproperty part:

var hasproperty : boolean = foo.hasownproperty("bar"); 

which apparently should work fine on anonymous object (thanks letting me know!).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -