This is my polyfill for call method
Function.prototype.mycall = (obj,...args)=>{
if(typeof this!="function") throw new Error("mycall can only be used on a function")
obj.myFunc = this
obj.myFunc(...args)
delete obj.myFunc
}
And this is my whole script including the polyfill
obj = {
name: "sai",
age: 25
}
sample = ()=>{
console.log(`I am ${this.name} and is ${this.age} years old`)
}
Function.prototype.mycall = (obj,...args)=>{
if(typeof this!="function") throw new Error("mycall can only be used on a function")
obj.myFunc = this
obj.myFunc(...args)
delete obj.myFunc
}
sample.mycall(obj)
But when I look at my console, I am getting this error
task.js:12 Uncaught Error: mycall can only be used on a function
at Function.mycall (task.js:12:39)
at task.js:22:8
Function.mycall @ task.js:12
(anonymous) @ task.js:22
Can anyone please help me on why I am getting this error?