Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some comments detailing the contract of the <code>multiplyByTwo</code> function would be helpful here:</p> <pre><code>// multiplyByTwo // num num num (num -&gt; x) -&gt; x[] function multiplyByTwo(a, b, c, callback) { ... </code></pre> <p>This means that the function takes four arguments, and returns an array of <code>x</code>. <code>x</code> can be any type. The first three arguments are numbers. The fourth argument to the function is actually a function itself. This function takes a number, and returns an <code>x</code>. Again, <code>x</code> can be any type, but it is the same type throughout the contract.</p> <p>Inside the <code>multiplyByTwo</code> function, the callback function is called once for each of the other arguments. The result of each of these calls is added to an array, which is the return value of <code>multiplyByTwo</code>.</p> <p>The <code>arguments</code> variable is a special variable in javascript, which, inside the scope of a function, gives access to all of the arguments to that function, as an array.</p> <p>The callback function is bound to the name <code>callback</code> in the scope of the <code>multiplyByTwo</code> function. It can then be called as any other function, such as by appending parentheses and arguments. The anonymous function that you gave when you called <code>multiplyByTwo</code> can then be referenced by that name.</p> <p>So, in the example given, <code>multiplyByTwo</code> is called with four arguments: <code>1</code>, <code>2</code>, <code>3</code>, and an anonymous function. Inside the scope of the <code>multiplyByTwo</code> function, these arguments are bound to the variables <code>a</code>, <code>b</code>, <code>c</code>, and <code>callback</code>, respectively. These arguments can also be referenced through the special <code>arguments</code> array. In the example, both methods are used to reference the arguments. The first three are referenced using the <code>arguments</code> array inside a loop, and the fourth argument is referenced using its name, as in <code>callback(...)</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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