Binding this with Function.bind in Javascript


Bind a specific object to this in a function.

Source Code

let person = {
  name: 'John'
};
function introduce() {
  console.log(`Hello, my name is ${this.name}`);
}
let boundIntroduce = introduce.bind(person);
boundIntroduce(); // "Hello, my name is John"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments