const user = {
name: "Yauheni",
 
regularFunction() {
console.log(this.name); // Yauheni
},
 
// arrowFunction: () => {
// console.log(this.name); // undefined
// },
};
 
// user.regularFunction();
// user.arrowFunction()
 
function introduce(greeting, symbol) {
console.log(`${greeting}, я ${this.name}${symbol}`);
}
 
const boundIntroduce = introduce.bind(user, "Привет");
const boundIntroduceCall = introduce.call(user, "Привет", "!");
const boundIntroduceApple = introduce.apply(user, ["Привет", "!"]);
 
 
boundIntroduce("!")
 
Function.prototype.myBind = function (context, ...boundArgs) {
if (typeof this !== "function") {
throw new TypeError("myBind must be called on a function");
}
 
const originalFunction = this;
 
return function (...callArgs) {
return originalFunction.apply(context, [
...boundArgs,
...callArgs,
]);
};
};
 
function introduceMybind(greeting, punctuation) {
return `${greeting}, меня зовут ${this.name}${punctuation}`;
}
 
 
const boundIntroduceMyBind = introduceMybind.myBind(user, "Привет");
 
console.log(boundIntroduceMyBind("!"));
// Привет, меня зовут Yauheni!
Code will run automatically after changes.
Code runs in an isolated environment.