I personally always use “is” for type-testing. I’ve always considered using “as” and null testing as counter-intuitive.
I only use “as” for type casting to make the compiler happy. I’m fine with switching it if there’s reason to do so. On Jan 7, 2016, at 11:55 PM, Alex Harui <aha...@adobe.com> wrote: > How many of you use the "as" keyword as part of a test? IOW things like: > > var foo:SomeType = someVar as SomeType; > if (foo == null) > > IMO, I have yet to use "as" in this way in the FlexJS framework. I just > use it to make the compiler happy. IOW things like: > > var foo:SomeType = someVar as SomeType; > foo.someProp > > If foo really isn't of SomeType, I am going to get an NPE, but I know it > will never be null, I am just casting/coercing so the compiler will check > that someProp really exists on SomeType. > > The reason I'm asking is because the use of "as" as become a negative > factor in several cases: > 1) In JS, it results in a function call > 2) As Om noted yesterday, it doesn't work for Native JS types > 3) It causes unnecessary class dependencies which complicates the > goog.requires list > > Currently there is an @flexjsignorecoercion hack you can use to tell > FalconJX to skip code-generation for an "as" operation. However, we are > adding more and more of these, and they are more frequently the cause of > something not working, so I am thinking about flipping the logic and not > generating code for any "as" operation unless you specifically ask for it > via @flexjsgeneratecoercion or something like that. > > Thoughts? > -Alex >