Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Old thread I know, but still worth posting.</p> <blockquote> <p>const jonny1 : Person = new Person("jonny", 26); const jonny2 : Person = new Person("jonny", 26);</p> <p>is creating two completely different objects that will not compare using ==, guess I don't see why it's any more of a road block because of as3</p> </blockquote> <p>The problem with AS3/JavaScript/EcmaScript is not that they create two different, equivalent objects.</p> <p>The problem is that they cannot equate those two equivalent objects--only identity works, since there is no equals or hashCode methods that can be overriden with class-specific comparison logic.</p> <p>For Map implementations such as dynamic Object or Dictionary, this means that you have to either use Strings or references as keys: you cannot recover objects from a map using different but equivalent objects.</p> <p>To work around that problem, people either resort to strict toString implementations (for Object maps) which is undesirable, or to instance control for Dictionaries, as in @back2dos example, which introduces different problems (Also, note that @back2dos solution does not really guarantee unique Person instances since there is a time window during which asynchronous threads will be allowed to instantiate new Persons).</p> <p>@A.Levy's solution is good except that in general, hashCodes are not strictly required to issue unique values (they are meant to map entries to buckets allowing for fast lookups, wherein fine-grained differentiation is done through equals method).</p> <p>You need <strong>both</strong> a hashCode and an equals method, e.g.</p> <pre><code>public interface IEquable { function equals(object : Object) : Boolean; function hash():String; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload