flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin Mclean <jus...@classsoftware.com>
Subject [FlexJS] typeof X === 'undefined'
Date Sun, 19 Mar 2017 05:09:59 GMT

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.


1. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/undefined
2. https://jsperf.com/typeof-vs-undefined-check/37 <https://jsperf.com/typeof-vs-undefined-check/37>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message