I consider myself (at best) a mid-level JavaScript guy...and of course...I want to understand HOW some things are accomplished so I can write better code. As such, I've been looking under-the-hood of jQuery trying to uderstand it a little more about how certain things are accomplished.
For example:
jQuery handles the case where IE and Opera return items by name instead of ID by doing the following:
// HANDLE: $("#id")
else
{
var elem = document.getElementById( match[3] );
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem && elem.id != match[3] )
return jQuery().find( selector );
// Otherwise, we inject the element directly into the jQuery object
var ret = jQuery( elem || [] )
ret.context = document;
ret.selector = selector;
return ret;
}
...okay that's easy!
But a typical line of jQuery code chains a series of commands together:
$('#someElementId').fadeIn().css({ ...Some CSS Properties ... });
Now...I 'think' the chaining portion is handled in the following area:
jQuery.extend = jQuery.fn.extend = function() { ... };
I'm combing through this area...and I see HOW a single command is processed...but I don't really see WHERE or HOW a chain-of-commands are managed. So I am obviously missing something.
So My Question Is:
- How does jQuery implement chaining of selectors?