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

2026bad constructor?

Expand Messages
  • Stjepan Rajko
    Mar 9, 2011
    • 0 Attachment
      Hello,

      On the following code:

      function One(a, b, c) {
      ````this.value = a + b + c;
      }
      function Two(a, b, c) {
      ````this.value = c + b + a;
      }
      var which = Math.round(Math.random());
      var x = new (which ? One : Two) ("1", "2", "3");
      alert(x.value);

      JSLint gives:

      *Error:*

      Problem at line 8 character 31: Bad constructor.

      var x = new (which ? One : Two) ("1", "2", "3");
      **
      After a brief look at the ECMAscript spec I think this is valid code but I'm
      not 100% sure. In any case, I was wondering if anyone could help me
      understand why JSLint complains about this. It does seem to work as
      intended (randomly alerts either "123" or "321") in all browsers I tested.

      Thanks,

      Stjepan


      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic