create your own Function.prototype.call
2022年5月1日小于 1 分钟
Function.prototype.call
create your own Question
Function.prototype.call is very useful when we want to alter the this
of a function.
Can you implement your own myCall
, which returns the same result as Function.prototype.call
?
For the newest ECMAScript spec, thisArg
are not transformed. And not replaced with window in Strict Mode.
Your implementation should follow above spec and do what non Strict Mode does.
Function.prototype.call/apply/bind
and Reflect.apply should not be used.
Code
Function.prototype.mycall = function(thisArg, ...args) {
// your code here
}