手撕 apply和call
十月 14, 2020
本文共计:
142 字
预计阅读时长:
1分钟
前言
call
和apply
的区别,应该在于API
的使用上,call(context | null, args...)
,apply(context | null, [args...])
;
共同点在于都可以自调用函数
,硬绑定 上下文(this)
;
现在,开启手撕模式:
Sources
Call
1 | Function.prototype.myCall = function (context) { |
Apply
1 | Function.prototype.myApply = function (context) { |
The End
最后,其实是有问题的,问题原因请看如下 issue
;
查看评论