jQuery Plugin Options: Extend before or inside this.each block?
<p>I'm looking at the Plugin Authoring article at <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">http://docs.jquery.com/Plugins/Authoring</a> and saw this example in the Defaults and Options section:</p>

<pre><code>$.fn.tooltip = function( options ) {  
var settings = {
  'location'         : 'top',
  'background-color' : 'blue'
};
return this.each(function() {        
  // If options exist, lets merge them
  // with our default settings
  if ( options ) { 
    $.extend( settings, options );
  }
</code></pre>

<p>I don't fully understand why the .extend call is inside the this.each block? My first intuition would be to write it as:</p>

<pre><code>$.fn.tooltip = function( options ) {  
var settings = {
  'location'         : 'top',
  'background-color' : 'blue'
};
$.extend( settings, options || {} );

return this.each(function() { 
</code></pre>

<p>So I moved the .extend call above the return (and replaced the ugly if with a || {} - I assume that makes sense?).</p>

<p>Is there anything I'm not seeing here? Any weird closure related stuff maybe? As in: Modifying the settings globally vs. only on that call? (Edit: Apparently I am not - <a href="http://jsfiddle.net/fVSDH/" rel="nofollow">http://jsfiddle.net/fVSDH/</a> )</p>
