Loading ...
Sorry, an error occurred while loading the content.

480Re: option.browser

Expand Messages
  • pauanyu
    May 5, 2009
      --- In jslint_com@yahoogroups.com, "crlender" <crlender@...> wrote:
      > In your example, if foo is not declared, it will result in a
      > ReferenceError being thrown. This won't happen if you test with the
      > typeof operator. I think DC's point was about avoiding the reference
      > to 'window' when testing for a global variable, since 'window' is no
      > longer part of option.browser.
      > In addition to that, '!foo' converts a value to boolean, and some
      > host objects (especially in IE) are known to throw exceptions if
      > you try that. typeof is always safe*.
      > - Conrad
      > * Except, I think, in one weird Safari 2 bug when items of a
      > NodeList are checked, but I'd have to look that up.

      I see; thank you. Another question, why use:
      if (typeof console === 'object') {

      Instead of:
      if (console instanceof Object) {


      As far as I know, if "console" is null, typeof will return 'object', which would break the first code.

      P.S. I know what the point of Douglas' post is, but he brought up the idea of using typeof, and I was curious why he recommended it, rather than an alternative.
    • Show all 8 messages in this topic