An interesting situation with the AS3 hash. Does he really use strict equality, as the documentation says?

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

As for the key comparison method ... The Dictionary class allows you to create a dynamic set of properties that uses strict equality (===) to compare keys. When an object is used as a key, the object identifier is used to find the object, not the value returned when toString () is called on it.

If the dictionary uses strict equality, as indicated in the documentation, then how can num1 === num2 be false, and yet dic [num1] allows the same hash slot as dic [num2]?

+3
2

, Adobe, , , .

:

for (var key:* in dic) trace(getQualifiedClassName(key));//will give you 'String'

Array Object.

: int int, ( float, null undefined).

Dictionary , - String, . "" Object, .

, Object 2 , . Dictionary , , .

edit: , , :

Hacky? , ? ... 64- , , . 64- 64-, , .

64- 64- ints - , ( , - ).

( , float ) :

var f1:Number = 1000000000000003000000000.0;
var f2:Number = 1000000000000002000000000.0;
trace(f1 == f2);//false
trace(String(f1) == String(f2));//true ... kabooooom

, 2 64- ints, , , float, . , , , LightSpark. . , , , , , . .

, , , . , 64- int . , , XML JSON, .

. . , .

Greetz
back2dos

+2

, - . Dictionary , . , , .

, AS3 : NaN - NaN ( ). , NaN . , , "true" "undefined".

, , :

import flash.utils.Dictionary;
var num1:Number = Number.POSITIVE_INFINITY;
var num2:Number = 1 / 0;
var dic:Dictionary = new Dictionary( true );
trace(num1); // Infinity
trace(num2); // Infinity
dic[num1] = "A";
trace( num1 == num2 ); // true!!
trace( num1 === num2 ); // true!!
trace( dic[num1] ); //A
trace( dic[num2] ); //A

, , , AS3 , , . , , . NaN Infinity , , - false - , NaN .

-1

Source: https://habr.com/ru/post/1747062/


All Articles