实现思路
将函数设为对象的属性
执行该函数
删除该函数
1 | // 第一步 |
注意事项:
传入的参数并不确定
this 参数可以传 null,当为 null 的时候,视为指向 window
函数是可以有返回值的!
call 实现代码
1 | Function.prototype.call = function (context) { |
apply 实现代码
1 | Function.prototype.apply = function (context, arr) { |
bind 实现 polyfill
1 | if (!Function.prototype.bind) { |