Back to Top

Javascript bind()

Updated 26 December 2019

Hey, If you want to learn the Javascript bind() method then read this blog. You must read first call() and apply() methods here

Simple object with the method

bind1-1

In the above example, I just console an object method that will simply return this function. Now just come to bind() method

Syntax: obj.callingMethod.bind(boundObject);

bind() method created a new function and bound another object while calling an object method. This method doesn’t execute the invoked function because it returns a new function with the bounded object. Please see the following example

Start your headless eCommerce
now.
Find out More
bind2

In the above example, you will see a function will be displayed into the console. bind() method will bound an object nameObj but return a new function for later use.

Please see the directory by this code console.dir(personObj.getAddress.bind(nameObj));

bind3

In the above result, you can see nameObj object properties are bounded so you can use it by this keyword. You can now call the bounded function like this.

bind4

I hope you had a basic idea of the bind() method. Thanks for your time.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home