Re: [jQuery] Advantages of adding functions to jQuery

2007-03-15 Thread Jörn Zaefferer
Daniel MacDonald schrieb:
 I believe I got it, using:

 jQuery.log = {
   error : function() { ... },
   warning : function() { ... },
   debug : function() { ... },
 }; 

 as opposed to:

 var log = {
   error : function() { ... },
   warning : function() { ... },
   debug : function() { ... },
 }; 

 prevents a conflict with some other script that uses log in the global
 scope. Of course, I still have to watch out for other jQuery.log objects.
   
Right. But at least its safe to assume that any code that places itself 
in the jQuery namespace requires jQuery to run.

-- 
Jörn Zaefferer

http://bassistance.de


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] Advantages of adding functions to jQuery

2007-03-14 Thread Daniel MacDonald

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?
-- 
View this message in context: 
http://www.nabble.com/Advantages-of-adding-functions-to-jQuery-tf3404801.html#a9483351
Sent from the JQuery mailing list archive at Nabble.com.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Advantages of adding functions to jQuery

2007-03-14 Thread Michael Geary
 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/


Re: [jQuery] Advantages of adding functions to jQuery

2007-03-14 Thread Jörn Zaefferer
Daniel MacDonald schrieb:
 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?
   
Thats it! By putting everything into a single global object, there isn't 
the chance of colliding with other libraries or global objects in general.

Mike answered the other issue :-)

-- 
Jörn Zaefferer

http://bassistance.de


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Advantages of adding functions to jQuery

2007-03-14 Thread Erik Beeson
Like pseudo packages/namespaces.

--Erik

On 3/14/07, Jörn Zaefferer [EMAIL PROTECTED] wrote:
 Daniel MacDonald schrieb:
  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?
 
 Thats it! By putting everything into a single global object, there isn't
 the chance of colliding with other libraries or global objects in general.

 Mike answered the other issue :-)

 --
 Jörn Zaefferer

 http://bassistance.de


 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Advantages of adding functions to jQuery

2007-03-14 Thread Daniel MacDonald

I believe I got it, using:

jQuery.log = {
  error : function() { ... },
  warning : function() { ... },
  debug : function() { ... },
}; 

as opposed to:

var log = {
  error : function() { ... },
  warning : function() { ... },
  debug : function() { ... },
}; 

prevents a conflict with some other script that uses log in the global
scope. Of course, I still have to watch out for other jQuery.log objects.
thx


Jörn Zaefferer wrote:
 
 Daniel MacDonald schrieb:
 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?
   
 Thats it! By putting everything into a single global object, there isn't 
 the chance of colliding with other libraries or global objects in general.
 
 Mike answered the other issue :-)
 
 -- 
 Jörn Zaefferer
 
 http://bassistance.de
 
 
 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/
 
 

-- 
View this message in context: 
http://www.nabble.com/Advantages-of-adding-functions-to-jQuery-tf3404801.html#a9486114
Sent from the JQuery mailing list archive at Nabble.com.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/