On Oct 15, 2006, at 20:38, Jörn Zaefferer wrote:

> I'd like to point to a small change I made recently to the jQuery
> Plugins Authoring article, for all those who take others code as
> reference. The "reference code" to define defaults and parse  
> options now
> looks like this:
>
> jQuery.fn.pluginMethod = function(options) {
>   var settings = $.extend({
>     stuff: [5, 3, 6, 1],
>     name: "pete",
>     speed: 5
>   }, options || {});
>   // other plugin code
> };
>
> So far this is the shortest way to write that particular snippet, and
> I'd like to see it in your plugins :-)

That saves 11 characters (not counting whitespace) compared to  
original (see below), but makes code less readable (IMO). So depends  
what you are after. Clever code or readable code.

Authoring guidelines say "Always use jQuery instead of $ inside your  
plugin code - that allows users to change the alias for jQuery in a  
single place." Does this mean only the first line jQuery.fn... or  
should also extend be jQuery.extend()?

-cut-
jQuery.fn.pluginMethod = function(options) {
     var settings = {
         stuff: [5, 3, 6, 1],
         name: "pete",
         speed: 5
     };
     if(options) {
         $.extend(settings, options);
     };
};


-- 
Mika Tuupola
http://www.appelsiini.net/~tuupola/



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to