Singleton vs Singleton

Giganews Newsgroups
Subject: Singleton vs Singleton
Posted by:  Michael Haufe (\"TNO\") (t…@thenewobjective.com)
Date: Sun, 24 Jan 2010

From looking at the code below:
--------------------------------------------------
var Singleton1 = (function(){
    //...
    return {
        foo : function(){
            //...
        },
        bar : function(){
            //...
        }
    };
})();

var Singleton2 = new function(){
    //...
    this.foo = function(){
        //...
    };
    this.bar = function(){
        //...
    };
};
-----------------------------------------------

Is there a good reason why jslint should complain about Singleton2,
but not Singleton1?

jslint message:
-----------------------------------------------
Problem at line 13 character 18: Weird construction. Delete 'new'.

var Singleton2 = new function(){

Problem at line 21 character 2: Missing '()' invoking a constructor.

};
-----------------------------------------------

Replies