J
Jesse
Hey, I've got a question about self invoking functions in javascript.
What I'm doing is something similar to the following
myNamespace = {}; //namespace for holding any objects/functions
//helpModule as an example
myNamespace.HelpModule = new (function(){
this.abc = '123';
//lots of other code in here...
return this;
})();
However jsLint doesn't like that saying "Weird construction. Delete
'new'.".
But it seems to work fine, and the reason I'm using it is to have
"this" scope to the function instead of the window. I could just
define it as an object literal or do something similar to
myNamespace.HelpModule = (function(){
var obj = {};
obj.abc = '123';
return obj;
}();
but for some reason I like having the 'this' keyword
What I'm doing is something similar to the following
myNamespace = {}; //namespace for holding any objects/functions
//helpModule as an example
myNamespace.HelpModule = new (function(){
this.abc = '123';
//lots of other code in here...
return this;
})();
However jsLint doesn't like that saying "Weird construction. Delete
'new'.".
But it seems to work fine, and the reason I'm using it is to have
"this" scope to the function instead of the window. I could just
define it as an object literal or do something similar to
myNamespace.HelpModule = (function(){
var obj = {};
obj.abc = '123';
return obj;
}();
but for some reason I like having the 'this' keyword