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

Using the singleton pattern results in JSlint error

Expand Messages
  • klemen.slavic
    When constructing a singleton in JS using an anonymous constructor, JSlint returns a Weird construction error. Here s the code: /*globals A*/ A = new
    Message 1 of 2 , May 7, 2008
    • 0 Attachment
      When constructing a singleton in JS using an anonymous constructor, JSlint returns a "Weird construction" error. Here's the code:

      /*globals A*/
      A = new function () {
          this.hello = "world";
      }();


      Is there a way for JSlint to detect and ignore such constructs as valid singletons?
    • Douglas Crockford
      ... Drop the unnecessary new operator, then it will be correct.
      Message 2 of 2 , May 11, 2008
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "klemen.slavic" <krof.drakula@...>
        wrote:
        >
        > When constructing a singleton in JS using an anonymous constructor,
        > JSlint returns a "Weird construction" error. Here's the code:
        >
        > /*globals A*/
        > A = new function () {
        > this.hello = "world";
        > }();
        >
        > Is there a way for JSlint to detect and ignore such constructs as valid
        > singletons?

        Drop the unnecessary new operator, then it will be correct.
      Your message has been successfully submitted and would be delivered to recipients shortly.