I'm definitely open to changing the compiler. Not sure what the right answer is. Since we are theoretically writing AS, I'd lean away from using "void 0".
_responseHeaders is an Array, so in Flash, it cannot be undefined, only null. So, I think in code that is used in both SWF and JS, the developer will write if (_responseHeaders == null) Wouldn't that work on both platforms? I'd be tempted to just have the transpiler skip reporting any error if you write: if (_responseHeaders === undefined) Thoughts? -Alex On 3/18/17, 10:09 PM, "Justin Mclean" <jus...@classsoftware.com> wrote: >Hi, > >I was looking at HTTPService.as and noticed this: > >Given the variable _responseHeaders is declared is there any reason to do >this: >if (typeof _responseHeaders === 'undefined') { > >When this should work: >if (_responseHeaders === undefined) > >I note this [1] says to avoid the style currently used in the code and >other places (from a quick google search) suggest it's only needed for >very old browsers (IE8) and where you are concerned that undefined may of >been redefined. > >However changing this give an warning like so: >Illogical comparison with undefined. Only untyped variables (or >variables of type *) can be undefined. > >For code inside COMPILE_JS is this actually correct? Looks like a bug to >me. > >This can be got around by using “void 0” like so: >if (_responseHeaders === void 0) > >Seems to be a more modern way of doing the same thing and dosn’t raise a >warning. > >Both methods are faster by about 10% than typeof X === 'undefined' in >browsers I checked. [2] > >Thanks, >Justin > >1. >https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdeveloper >.mozilla.org%2Fen%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2 >Fundefined&data=02%7C01%7C%7C5606c4b8afdc40c66ee608d46e863c18%7Cfa7b1b5a7b >34438794aed2c178decee1%7C0%7C0%7C636254970223388353&sdata=GWAzyxYCvnUc9fx0 >DdU1HGOLIGwuSmOrZpYwTynYRoI%3D&reserved=0 ><https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdevelope >r.mozilla.org%2Fen%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects% >2Fundefined&data=02%7C01%7C%7C5606c4b8afdc40c66ee608d46e863c18%7Cfa7b1b5a7 >b34438794aed2c178decee1%7C0%7C0%7C636254970223388353&sdata=GWAzyxYCvnUc9fx >0DdU1HGOLIGwuSmOrZpYwTynYRoI%3D&reserved=0> >2. >https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjsperf.co >m%2Ftypeof-vs-undefined-check%2F37&data=02%7C01%7C%7C5606c4b8afdc40c66ee60 >8d46e863c18%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C63625497022338835 >3&sdata=DKX0LzIj41nCWNrbiVtYKB23vMJBlwMVhP8dCHHlivc%3D&reserved=0 ><https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjsperf.c >om%2Ftypeof-vs-undefined-check%2F37&data=02%7C01%7C%7C5606c4b8afdc40c66ee6 >08d46e863c18%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C6362549702233883 >53&sdata=DKX0LzIj41nCWNrbiVtYKB23vMJBlwMVhP8dCHHlivc%3D&reserved=0> >