I am not asking what is the appropriate syntax for chaining, I know it could be something like:
$('myDiv').removeClass('off').addClass('on');
However I'm really curious to understand the inner working of it, as far as I know chaining is one of the advantages against other famous frameworks but this us to much abstraction for a novice programer like me, I'm sure there is someone out there that can provide me with a explanation that allows me to understand how chaining works.
Thanks!
Eaxample
All that it is doing is returning a reference to
this
when the method finishes. Take this simple object for example:You could chain these calls all day because you return a reference to
this
:jQuery simply performs an operation, then returns
this
.Basically the first function call
$('myDiv')
returns a jQuery object, then each subsequent call returns the same one.Loosely,