Implement call()

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 call()

Approach

Attach the target function as a temporary method on the context object using a Symbol key to avoid property collisions. Invoke it via context[fnKey](...args) so that this resolves to context, then clean up by deleting the temporary property.

Complexity Analysis

Time
O(1)
Space
O(1)

Pattern

Context Binding Polyfill

Why It Works

When a function is called as a method of an object (obj.fn()), JavaScript sets this to the object. By temporarily attaching the function to the desired context, we leverage implicit this binding.

Updated Feb 2026