What is binding in JavaScript?

Image taken from Unsplash

In JavaScript the bind() method creates a new function and sets this to a specific value.

For instance, here we have a simple object:

Then we use the bind() method to set the context of this to the person object:

When it is all done and the function is invoked it will look like this:

--

--

--

A web developer with a passion for technology and ambition to keep growing in programming.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Polyfill for bind(), Step-by-step

The use of ReplaySubject(1) vs BehaviourSubject in RxJS.

Lighthouse CI — Web incremental change with confidence

Test Automation using NightWatch — Part 1

Learn Cypress from zero to hero in 3 Steps

Using JavaScript Code in Flutter Web

Improving perceived interface responsiveness on public kiosks

Becoming a web developer definitely comes with its struggles.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Som Ramnani

Som Ramnani

A web developer with a passion for technology and ambition to keep growing in programming.

More from Medium

8 JavaScript array method you must know

Old Habits Die Hard, But Getting New Ones is Essential. Tips on Getting the Most Out of TypeScript

Const myFirstJavascriptBlog = “Declaring Variables”

Should Frontend Devs Care About Performance?