前言
在 JavaScript 中,bind 方法是用来改变函数的 this 指向的。
实现
1 2 3 4 5
| Function.prototype.myBind = function(context) { return function(...args) { return this.apply(context, args) } }
|
如果你直接写
1 2 3 4 5
| function myBind(context) { return function(...args) { return this.apply(context, args) } }
|