bhylu.com

Advertisements

Function Bind

Bind creates a new function with a chosen receiver and optional leading arguments. It does not call the function immediately.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

function greet(prefix) { return prefix + this.name; }
const welcome = greet.bind({name: "Mira"}, "Hello, ");
console.log(welcome());

What happens

The bound function returns Hello, Mira.