Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>direction</code> and <code>loc</code> are defined in the scope of your callback function for 'click'. They are initialized every time you call that callback function -- at every click. <code>direction</code> is initialized by the 'data-dir' associated to the button and <code>loc</code> is initialized to the current value of <code>imgWidth</code> (which is a variable defined in the scope of your main function). </p> <p>After being initialized, <code>direction</code> and <code>loc</code> can be modify by your <code>if-else if</code> logic and they are then passed to the function <code>transition()</code>. (Note that <code>sliderIU</code> is also passed to <code>transition()</code>, but it is not necessary since it has the scope of your main function and it could be used directly within <code>transition()</code> without being passed as parameter <code>container</code>. However it might not be a bad idea to pass it as a parameter since it makes for clearer programming style when you can see from the arguments of a function on which values it is acting.)</p> <p>The variable <code>current</code> which is used in the callback-click function is not defined in the scope of that callback-click function but has the main function scope (defined at the start of the main function). This is necessary because you want to change its value --and remember the change-- each time the button is clicked. The callback-click function is a <em>closure</em> since it has access (read+write) to the external variable <code>current</code>. The variables <code>direction</code> and <code>loc</code> have nothing to do with closures; they are just variables that you pass to a function.</p>
 

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