How does chaining work? (In JavaScript.)

How does chaining work? (In JavaScript.)


When I chain jQuery functions, say...
$("#myId").css("background-color","red").show();
What exactly is happening in JavaScript?
$ is just an identifier, so the first pair of parens says I'm calling
a function with a string as a parameter. But isn't the rest of the
chain going to go looking for something deep inside $?
What am I missing? Does it all go in somehow as a parameter? Why does
it work? What part of the source can I look at to see this in action?
Suppose I wanted to make some kind of Forth-like chain of RPN this
way, or an APL-like set of chainable matrix operators. How would I go
about that?