为了保障原创作者在本站发表文章的利益, 并维护本站原创的精神, 特声明: RIAShanghai对有以下任何情况之一的文章将不通知作者并直接进行快意删除:
- 非原创, 或者原创但一文多发;
- 各种形式的广告与吹擂;
- 不符合本站文章格式.
欢迎各位读者监督. 谢谢合作. 另: 作为Adobe正式的UG, 我们将把Adobe不定期分发的软件,书籍及各种纪念品赠送给发文活跃的作者, 共同进步.
In Actionscript, primitive types include the following 5 - Number, int, uint, Boolean, String (and strictly speaking, null & void). Primitive types equality is simple. There are three rules:
1. direct comparisons of numeric types are allowed and work as most people expected;
2. use PRIMITIVE_TYPE(ValueOfAnotherType) to convert types, e.g, String(2.0);
3. for primitive types, there is no difference between == and === (strict equality).
Testing:
var num:Number = 2.0;
var integer:int = 2;
var string:String = "2";
trace("num == integer: " + (num == integer));
// trace("num == string: " + (num == string)); // Error: 1176: Comparison between a value with static type Number and a possibly unrelated type String.
trace("num == Number(string): " + (num == Number(string)));
trace("String(num) == string: " + (String(num) == string));
//trace("integer == string" + (integer == string));
trace("integer == int(string): " + (integer == int(string)));
trace("String(integer) == string: " + (String(integer) == string));
trace("num === integer: " + (num === integer));
trace("String(integer) === string: " + (String(integer) === string));and the corresponding output:
num == integer: true num == Number(string): true String(num) == string: true integer == int(string): true String(integer) == string: true num === integer: true String(integer) === string: true
Note: AS stores primitive values internally as immutable objects. For immutable objects, passing by reference is the same as passing by value.