Adobe specifically states about Dictionaries:
the object’s identity is used to look up the object, and not the value returned from calling toString()
However when I run
if(myInstance in myDictionary) { ... }
To see if myInstance already exists as a ‘key’ in myDictionary, myInstance.tostring get’s called!
Anyone know why or a way around it?
The
inkeyword is generally used with object properties, which are strings. Consider the difference between afor eachloop versus afor inloop.We typically use the
for inloop to iterate over an object’s dynamic properties:So in your code snippet the
inkeyword is causing the call totoString().The correct way to test if a key exists is to test for
null: