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

2031RE: [jslint] bad constructor?

Expand Messages
  • Rob Richardson
    Mar 9, 2011
      Your code is a perfect example of "clever" -- one of the best tools a coder
      has for showing their ingenuity and skill while simultaneously confusing
      people reading the code later. I grant that it is more lengthily to make
      your intentions clear, but to do so would almost certainly lead to a faster
      understanding for you and others in a month when you're debugging it. Use
      this rule of thumb consistently and it'll lead to higher productivity and
      lower maintenance costs for all involved.


      -----Original Message-----
      From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
      Behalf Of Stjepan Rajko
      Sent: Wednesday, March 09, 2011 8:13 AM
      To: jslint_com@yahoogroups.com
      Subject: [jslint] bad constructor?


      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");

      JSLint gives:


      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.



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