Webolution Designs

Bind

Share This Post

Bind allows us to copy a function. Why would we want to do this? By copying it, we change the context of “this” for the entire new function. Here is an example…

let animal = {
    animalName: ‘Bongo’,
    getName: function(){
        return this.animalName;
    }
};
let newAnimalName = { animalName: ‘George’ };
let newAnimal = animal.getName.bind(newAnimalName); console.log(newAnimal()); 

The output would be “George”. This was possible because we used bind to copy the original function to the newAnimal function. This also allowed us to change the “this” context to newAnimalName at the same time.

Happy Coding!

Clay Hess

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Code

Curriculum Innovation or Confusion

It is an early Monday morning just prior to the beginning of the semester.  A faculty member walks into the institution where he teaches.  He

Code

Creating a Promise

Promises are used for asynchronous code. It is a temporary holder for a value that gets returned by an asynchronous call. For example, a call

Do You Want To Boost Your Business?

drop us a line and keep in touch

Excuse Our Mess! We are currently remodeling!

We are currently in the process of redesigning our site. We appreciate your patience as some areas of our site show chipping and paint peeling. We hope to have it sparkling soon!

small_c_popup.png

Learn how we helped 100 top brands gain success.

Let's have a chat