I understand that in JavaScript all functions are objects which is why
we can both call jQuery with arguments $() while also being able to
access methods with dot notation.
What I am less sure about is how,
when we pass in css selectors into the jQuery function, it instantly
returns a jQuery object. I am looking through the (old) annotated
source code (which i realise has changed significantly - but i just
want to understand the very basics of what jQuery is doing).
This is the part of the annotated code that I find confusing.
Define
a local copy of jQuery. The jQuery object is actually just the init
constructor 'enhanced'.
var jQuery = function( selector, context ) {
return new jQuery.fn.init( selector, context, rootjQuery );
},