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

Why is this a weird condition?

Expand Messages
  • aceblchboy
    Assuming that type is a MIME type and href is a URL, why is this a weird condition? matched = ((Boolean(~type.indexOf( .jpeg )) &&
    Message 1 of 2 , Jul 23, 2012
    View Source
    • 0 Attachment
      Assuming that type is a MIME type and href is a URL, why is this a weird condition?

      matched = ((Boolean(~type.indexOf(".jpeg")) && Boolean(~href.indexOf(".jpeg"))) || (Boolean(~type.indexOf(".jpeg")) && Boolean(~href.indexOf(".jpg"))) || (Boolean(~type.indexOf(".gif")) && Boolean(~href.indexOf(".gif"))) || (Boolean(~type.indexOf(".png")) && Boolean(~href.indexOf(".png"))) || (Boolean(~type.indexOf(".ico")) && Boolean(~href.indexOf(".ico"))) || (Boolean(~type.indexOf(".svg")) && Boolean(~href.indexOf(".svg"))));

      I suspect that something broke in the "weird condition" condition since JSLint is now throwing weird condition for only the first instance of !!~foo.indexOf("bar") per condition and that if I make it into a Boolean as above, it doesn't complain about the second instance appearing.
    • douglascrockford
      ... Thanks. Please try it now.
      Message 2 of 2 , Jul 23, 2012
      View Source
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "aceblchboy" <aceblchboy@...> wrote:
        >
        > Assuming that type is a MIME type and href is a URL, why is this a weird condition?
        >
        > matched = ((Boolean(~type.indexOf(".jpeg")) && Boolean(~href.indexOf(".jpeg"))) || (Boolean(~type.indexOf(".jpeg")) && Boolean(~href.indexOf(".jpg"))) || (Boolean(~type.indexOf(".gif")) && Boolean(~href.indexOf(".gif"))) || (Boolean(~type.indexOf(".png")) && Boolean(~href.indexOf(".png"))) || (Boolean(~type.indexOf(".ico")) && Boolean(~href.indexOf(".ico"))) || (Boolean(~type.indexOf(".svg")) && Boolean(~href.indexOf(".svg"))));
        >
        > I suspect that something broke in the "weird condition" condition since JSLint is now throwing weird condition for only the first instance of !!~foo.indexOf("bar") per condition and that if I make it into a Boolean as above, it doesn't complain about the second instance appearing.



        Thanks. Please try it now.
      Your message has been successfully submitted and would be delivered to recipients shortly.