Implement apply()

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Implement apply()

Approach

Use the same Symbol-based temporary method technique as call(), but accept arguments as an array instead of individually. Default the args parameter to an empty array to handle calls with no arguments. Spread the array when invoking the temporary method.

Complexity Analysis

Time
O(n)
Space
O(1)

Pattern

Context Binding Polyfill

Why It Works

Apply is identical to call except it takes arguments as a single array, which is then spread. This was historically important before the spread operator existed for passing dynamic argument lists.

Updated Mar 2026