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

2266[jslint] Re: option.type

Expand Messages
  • spence.randall@ymail.com
    Jun 6, 2011
    • 0 Attachment
      Here is the code snippet in question:

      Original:
      element.style.filter = 'alpha(opacity=' + value * 100 + ')';
      Error: Type inconsistency: string and number

      with String():
      element.style.filter = 'alpha(opacity=' + String(value * 100) + ')';
      No error.

      with .toString():
      element.style.filter = 'alpha(opacity=' + (value * 100).toString() + ')';
      Also no error. I think this may make the intention of the code clearer.

      Either method produces the expected result.

      -Randall








      --- In jslint_com@yahoogroups.com, Erik Eckhardt <erik@...> wrote:
      >
      > I think it's value.toString() not String(value). Correct me if I'm wrong.
      >
      > On Mon, Jun 6, 2011 at 2:48 PM, spence.randall@... <
      > randall@...> wrote:
      >
      > >
      > >
      > >
      > >
      > > > Has anyone tried the new type consistency checking?
      > >
      > > I gave it a try, and I was fully expecting to see a mass of errors, but was
      > > pleasantly surprised when I only had one.
      > >
      > >
      > > > Has anyone found it to be useful?
      > >
      > > In the case of the actual error it flagged, I'm not sure. It was a "value"
      > > parameter in a setStyle function that could either be a string or a number.
      > > If the property that was being set was opacity and the browser was
      > > determined to be IE, it multiplies the value by 100 to get the proper
      > > setting for the filter. In this case wrapping the calculation in String()
      > > appears to satisfy JSLint. Would this be the proper approach?
      > >
      > > -Randall
      > >
      > >
      > >
      >
      >
      > [Non-text portions of this message have been removed]
      >
    • Show all 9 messages in this topic