Interesting AS3 hash situation. Is it really using strict equality as the documentation says?

Posted by Triynko on Stack Overflow See other posts from Stack Overflow or by Triynko
Published on 2010-05-25T17:27:26Z Indexed on 2010/05/25 18:41 UTC
Read the original article Hit count: 249

Filed under:
|
|
|
|

AS3 Code:

import flash.utils.Dictionary;
var num1:Number = Number.NaN;
var num2:Number = Math.sqrt(-1);
var dic:Dictionary = new Dictionary( true );
trace(num1); //NaN
trace(num2); //NaN
dic[num1] = "A";
trace( num1 == num2 ); //false
trace( num1 === num2 ); //false
trace( dic[num1] ); //A
trace( dic[num2] ); //A

Concerning the key comparison method... "The Dictionary class lets you create a dynamic collection of properties, which uses strict equality (===) for key comparison. When an object is used as a key, the object's identity is used to look up the object, and not the value returned from calling toString() on it."

If Dictionary uses strict equality, as the documentation states, then how is it that num1 === num2 is false, and yet dic[num1] resolves to the same hash slot as dic[num2]?

© Stack Overflow or respective owner

Related posts about flash

Related posts about dictionary