bind привязка контекста (this)

let user = {
    firstName: "John"
};
    
function func() {
    console.log(this.firstName);
}
    
//func(); // Выдаст ошибку так как this = undefined
    
let funcUser = func.bind(user); // так мы привяжем this внутри функции к user
funcUser(); // John

Подробнее тут https://learn.javascript.ru/bind

Last updated