Another note. There are 3 ways to cast and all of them suck in one

way or another!


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3956 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-03-17 01:19:15 +00:00
parent 7422b1e986
commit d1b997b9ff
+19
View File
@@ -195,6 +195,25 @@ ActionScript
var o1 :String = someObject;
// checked at runtime, throws TypeError if failure
Also, when the compiler is in strict mode it flags this code, so
we can't win.
I will sum up in a table:
* cast using "obj as Type"
+ helps compile-time type checking
- turns non-castable objects into null rather than generating an exception
* casting using "Type(obj)"
+ helps compile-time type checking
- will coerce primitive types between each other, the most annoying
problem being:
var o1 :Object = null;
var s1 :String = String(o1);
assert(s1 === "null");
* implicit casting ("var s :String = o")
+ it will generate a proper TypeError at runtime
- no compile-time checking, strict compiler generates an error (!!!)
- Pitfall! This is perfectly legal:
var b :int = 3;