When I read the question for the first time even I was totally blank. The very next thought came to my mind was "Is it really possible?".
Well the answer is YES. It is possible for an anonymous function to refer itself through the use of arguments.callee.
arguments is a local variable for a function object. callee is one of the properties of arguments. arguments.callee allows anonymous function to refer to itself, which is necessary for recursion. Here is an example:
Example: In this example, I will use arguments.callee within an anonymous function which is used as a callback for show() and hide() methods.
Demo:
Show the API list
- ID Selector ("#id")
Select an element based on the id value. For id selectors, jQuery uses the JavaScript function document.getElementById(), which is extremely efficient. When another selector is attached to the id selector, such as h2#pageTitle, jQuery performs an additional check before identifying the element as a match. - :first Selector
Selects the first matched element. The :first pseudo-class is equivalent to :eq(0). It could also be written as :lt(1). While this matches only a single element, :first-child can match more than one: One for each parent. - :last Selector
Selects the last matched element. Note that :last selects a single element by filtering the current jQuery collection and matching the last element within it. - Mouse Event - click()
Bind an event handler to the "click" JavaScript event, or trigger that event on an element. The click event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed and released. Any HTML element can receive this event. - show(duration, [ callback ] )
Display the matched elements. When a duration is provided, .show() becomes an animation method. The .show() method animates the width, height, and opacity of the matched elements simultaneously. If supplied, the callback is fired once the animation is complete. - hide(duration, [ callback ] )
Hide the matched elements. When a duration is provided, .hide() becomes an animation method. The .hide() method animates the width, height, and opacity of the matched elements simultaneously. When these properties reach 0, the display style property is set to none to ensure that the element no longer affects the layout of the page. If supplied, the callback is fired once the animation is complete.
No comments:
Post a Comment