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

Constructor Oddity

Expand Messages
  • Merlin
    With The Good Parts set: /*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true, regexp: true, plusplus: true, bitwise: true */ JSLint
    Message 1 of 2 , Jan 12, 2011
    • 0 Attachment
      With The Good Parts set:

      /*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true, regexp: true, plusplus: true, bitwise: true */

      JSLint Edition 2011-01-09 is happy with:

      var XXX = (function () {
      "use strict";
      // ...
      var itself = function (pattern) {
      var code;
      // ...
      return code;
      };

      return itself;
      }());

      var code = XXX("010");

      but not with:

      var XXXx = (function () {
      "use strict";
      // ...
      var itself = function (pattern) {
      var code;
      // ...
      return code;
      };

      return itself;
      }());

      var code = XXXx("010");

      Error:
      Problem at line 13 character 12: Missing 'new' prefix when invoking a constructor.

      var code = XXXx("010");

      This is independent of the setting of newcap.

      It seems to depend on the use of lowercase letters in the name.

      Harry.
    • Douglas Crockford
      ... This is the convention: Ordinary variables start with lower case. Global variables are all upper case. Global variables should be as rare as hen s teeth
      Message 2 of 2 , Jan 12, 2011
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Merlin" <g7awz@...> wrote:
        >
        > With The Good Parts set:
        >
        > /*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true, regexp: true, plusplus: true, bitwise: true */
        >
        > JSLint Edition 2011-01-09 is happy with:
        >
        > var XXX = (function () {
        > "use strict";
        > // ...
        > var itself = function (pattern) {
        > var code;
        > // ...
        > return code;
        > };
        >
        > return itself;
        > }());
        >
        > var code = XXX("010");
        >
        > but not with:
        >
        > var XXXx = (function () {
        > "use strict";
        > // ...
        > var itself = function (pattern) {
        > var code;
        > // ...
        > return code;
        > };
        >
        > return itself;
        > }());
        >
        > var code = XXXx("010");
        >
        > Error:
        > Problem at line 13 character 12: Missing 'new' prefix when invoking a constructor.
        >
        > var code = XXXx("010");
        >
        > This is independent of the setting of newcap.
        >
        > It seems to depend on the use of lowercase letters in the name.

        This is the convention:

        Ordinary variables start with lower case.

        Global variables are all upper case. Global variables should be as rare as hen's teeth and should stick out like a sore thumb.

        Constructor functions are CamelCase with an initial capital.
      Your message has been successfully submitted and would be delivered to recipients shortly.