I have tried making bind polyfill using this link
It works fine when I use "console.log". But when I return something from the function, it returns undefined
Code:
let person1 = {
name: "John",
age: 25,
};
let showDetails = function () {
let y = `${this.name} - ${this.age}`;
// console.log(y) -> works fine
return y;
};
Function.prototype.myBind = function (...args) {
let that = this;
params = args.slice(1);
return function (...args1) {
that.apply(args[0], [...params, ...args1]);
};
};
let showDetailsBind = showDetails.myBind(person1);
console.log(showDetailsBind()); // returns -> undefined
Problem with this polyfill is, default bind function works completely fine with same procedure.