In JavaScript, you can directly “use” the return value of a function call without assigning a value to a variable. Here is an example below:
var john = { me: function() { alert('...John'); } } var foo = { call: function() { alert('You called..'); return this;
Now to the method call:
If you
$(selector).show()
then the selected items are displayed. show again returns a set of selected items (same items selected by $(selector) ). This allows us to call another method on them: parent() selects (returns) the parent nodes of these elements (so we have a different set now), and the second show() works with this new (parent) set (and returns the parent set).
So
$(selector).show().parent().show()
will display the selected items and their parents.
The whole concept is called a free interface and is achieved using a chain of methods .
Felix kling
source share