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

Re: [jslint] Re: option.browser

Expand Messages
  • Marcel Duran
    ... typeof will always return a string result, hence you have a guarantee you ll get something to test against, on the other hand when testing with: if
    Message 1 of 8 , May 8, 2009
      On Tue, May 5, 2009 at 9:47 AM, pauanyu <pcxunlimited@...> wrote:

      > 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.
      >
      >



      typeof will always return a string result, hence you have a guarantee you'll
      get something to test against, on the other hand when testing with:

      if (console instanceof Object) {

      if console isn't declared you'll get a ReferenceError when trying to use
      instanceof. You likely won't have problems on firefox w/ firebug which has
      the console declared.


      --
      Marcel Duran


      [Non-text portions of this message have been removed]
    • douglascrockford
      The browser predefinition list has gotten a lot shorter: /*global clearInterval: false, clearTimeout: false, document: false, event: false, frames: false,
      Message 2 of 8 , Feb 11, 2011
        The browser predefinition list has gotten a lot shorter:

        /*global clearInterval: false, clearTimeout: false,
        document: false, event: false, frames: false,
        history: false, Image: false, location: false,
        name: false, navigator: false, Option: false,
        parent: false, screen: false, setInterval: false,
        setTimeout: false, XMLHttpRequest: false */

        The window.* methods and related properties have been removed.
        It is generally a bad idea to be poking at the window object,
        but if you must, do it explicitly. Write

        window.addEventListener(...)

        and not

        addEventListener(...)

        because the implicit form fails in strict mode. When a function is called as a function, this will be bound to undefined. In sloppy mode, this was bound to the global object, which was a bad idea, which enabled the implicit form, which was also a bad idea.
      • Rob Richardson
        I see setTimeout (and cousins) are still in the browser defined list, but would you recomend the same rule of thumb be true for these? E.g. would you
        Message 3 of 8 , Feb 11, 2011
          I see setTimeout (and cousins) are still in the browser defined list, but
          would you recomend the same rule of thumb be true for these? E.g. would you
          recommend "window.setTimeout( func...." rather than "setTimeout( func...."?

          Rob


          -----Original Message-----
          From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
          Behalf Of douglascrockford
          Sent: Friday, February 11, 2011 8:17 AM
          To: jslint_com@yahoogroups.com
          Subject: [jslint] option.browser

          The browser predefinition list has gotten a lot shorter:

          /*global clearInterval: false, clearTimeout: false,
          document: false, event: false, frames: false,
          history: false, Image: false, location: false,
          name: false, navigator: false, Option: false,
          parent: false, screen: false, setInterval: false,
          setTimeout: false, XMLHttpRequest: false */

          The window.* methods and related properties have been removed.
          It is generally a bad idea to be poking at the window object,
          but if you must, do it explicitly. Write

          window.addEventListener(...)

          and not

          addEventListener(...)

          because the implicit form fails in strict mode. When a function is called as
          a function, this will be bound to undefined. In sloppy mode, this was bound
          to the global object, which was a bad idea, which enabled the implicit form,
          which was also a bad idea.
        • Douglas Crockford
          ... They are global functions, not methods of the window object, so they work correctly without the window. prefix.
          Message 4 of 8 , Feb 11, 2011
            --- In jslint_com@yahoogroups.com, "Rob Richardson" <erobrich@...> wrote:
            >
            > I see setTimeout (and cousins) are still in the browser defined list, but
            > would you recomend the same rule of thumb be true for these? E.g. would you
            > recommend "window.setTimeout( func...." rather than "setTimeout( func...."?


            They are global functions, not methods of the window object, so they work correctly without the window. prefix.
          Your message has been successfully submitted and would be delivered to recipients shortly.