Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was just browsing through unanswered questions, and I'm not sure if this will help you at all but it may help somebody who stumbles upon this question.</p> <p>Using the <code>call()</code> method on a function object allows you to override the <em><code>this</code></em> object to be referenced by the function. You have demonstrated the expected results in your own code block.</p> <p>It can be noted that the <code>apply()</code> method performs pretty much the same functionality of <code>call()</code> except for the expected argument formats.</p> <p><code>call()</code> expects arguments in a comma separated format while <code>apply()</code> expects them in an array. With both, the first argument is the object that will be overriding <em><code>this</code></em>.</p> <h2>ECMA Spec</h2> <p>The <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf" rel="nofollow">ECMA specification (pdf warning)</a> has this to say about <code>call()</code> showing its use in changing the execution context for a specific function:</p> <blockquote> <p>13.2.1 [[Call]]</p> <p>When the [[Call]] internal method for a Function object F is called with a this value and >a list of arguments, the following steps are taken:</p> <ol> <li>Let funcCtx be the result of establishing a new execution context for function code using the value of F's [[FormalParameters]] internal property, the passed arguments List args, and the this value as described in 10.4.3.</li> <li>Let result be the result of evaluating the FunctionBody that is the value of F's [[Code]] internal property. If F does not have a [[Code]] internal property or if its value is an empty FunctionBody, then result is (normal, undefined, empty).</li> <li>Exit the execution context funcCtx, restoring the previous execution context.</li> <li>If result.type is throw then throw result.value.</li> <li>If result.type is return then return result.value.</li> <li>Otherwise result.type must be normal. Return undefined.</li> </ol> </blockquote>
    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. 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