> I'm having trouble seeing the advantage of adding static > functions to jQuery as in: > > jQuery.log = { > error : function() { ... }, > warning : function() { ... }, > debug : function() { ... }, > }; > > as opposed to: > > function log() { ... } > log.prototype.error = function() { ... } > log.prototype.warning = function() { ... } > log.prototype.debug = function() { ... } > > It seems the former opens up the door to unintended closures. > What are the benefits of doing it this way as opposed to the > traditional non-jQuery way?
I don't see any closures in that code. The jQuery.log = { ... } is not a function and doesn't introduce a closure. This object literal is just a handy way of creating some static functions. IOW, these are identical: jQuery.log = { error : function() { ... }, warning : function() { ... }, debug : function() { ... }, }; jQuery.log = {}; jQuery.log.error = function() { ... }; jQuery.log.warning = function() { ... }; jQuery.log.debug = function() { ... }; Your code with the log.prototype stuff is something different entirely. You're creating a log() constructor and giving it some methods. (BTW, by convention, you would usually call it Log() instead of log() because it's used as a constructor.) So you would need to do this to use it: var log = new Log; log.debug( ... ); The use of static functions avoids the need to construct an object. You can merely use: jQuery.log.debug( ... ); Not sure if I answered your question, but those are a few thoughts on it anyway... :-) -Mike _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/