Implement bind()

Hard
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 bind()

Approach

Return a new function that closes over the original function reference, the bound context, and any partially applied arguments. When the returned function is called, concatenate the bound args with the new call args and delegate to originalFn.apply(context, allArgs). This enables both full binding and partial application.

Complexity Analysis

Time
O(1)
Space
O(n)

Pattern

Partial Application

Why It Works

The returned closure captures the original function and context permanently. Combining bound args with call-time args enables currying-like partial application where some arguments are pre-filled.

Updated Feb 2026