class Pet {
constructor(name="Mister Anon") {
this.name = name;
this.sound = this.sound.bind(this);
}
sound() {
console.log(`My name is ${this.name}`);
}
}
let dog = new Pet("Bread");
let method = dog.sound;
method(); // My name is Bread
// а без бинда в конструкторе будет ошибка из-за то что this - undefined
let method = dog.sound.bind(dog);
method();