Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>.click()</code> function in jQuery except as first parameter a function. In Javascript function are value, as well as a primitive value or an object. Functions are <a href="http://en.wikipedia.org/wiki/First-class_citizen">first-class citizens</a>.</p> <p>If you use <code>function1(event)</code> as a parameter, the function will be executed, because this is the semantic of the brachet after the function name. So the <code>.click()</code> jQuery function will receive the output of the function, which is not the expected type.</p> <p>Passing the function name as a parameter means that you are passing the function (actually, a reference to the function), not the result of the function invocation. And the function will be called when the click event will be triggered. The function in this case is called "<em>callback</em>".</p> <p>Callbacks are very importants in Javascript, since the event-driven behaviour is the main reason for using a client-side scripting.</p> <p>The concept behind the callback system is </p> <pre><code>//the click function function doSomething(callback){ //in your case the event is the argument that jQuery will prepare for you var argument = produceTheArgument(); //doSomething is in charge to invoke the function, passing the argument callback(argument); } //your function function myCallback(argument){ //your function will consume the argument } //my callback is passed as a reference, not invoked doSomething(myCallback); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload