S
Scott Sauyet
(I know I've seen a discussion of this here not too long ago, but
search is failing me. Any pointers to prior threads would be
appreciated.)
I'm pretty sure posters here had some reasonable critiques of using
this style to declare a singleton:
var singleton = new function() {
var privateProp1 = //...
var privateFn = function(...) {...}
this.publicProp1 = // calculated using privateProp1 and
privateFn1
this.publicProp2 = // calculated using privateProp1 and
privateFn1
};
Obviously I could do this instead:
var singleton = (function() {
var privateProp1 = //...
var privateFn = function(...) {...}
return {
publicProp1: // calculated using privateProp1 and privateFn1,
publicProp2: // calculated using privateProp1 and privateFn1
};
};
But the former syntax seems somewhat cleaner. Are there good reasons
not to use it?
Thanks for any feedback,
search is failing me. Any pointers to prior threads would be
appreciated.)
I'm pretty sure posters here had some reasonable critiques of using
this style to declare a singleton:
var singleton = new function() {
var privateProp1 = //...
var privateFn = function(...) {...}
this.publicProp1 = // calculated using privateProp1 and
privateFn1
this.publicProp2 = // calculated using privateProp1 and
privateFn1
};
Obviously I could do this instead:
var singleton = (function() {
var privateProp1 = //...
var privateFn = function(...) {...}
return {
publicProp1: // calculated using privateProp1 and privateFn1,
publicProp2: // calculated using privateProp1 and privateFn1
};
};
But the former syntax seems somewhat cleaner. Are there good reasons
not to use it?
Thanks for any feedback,