var name = "她";
var o = {
name: "你",
};
function fn(a, b) {
console.log(a + b + this.name);
}
Function.prototype._bind = function(obj, ...args) {
// 返回一个新函数
return (...arr) => {
return this.call(obj, ...args, ...arr); // this即fn
};
};
fn._bind(o, '我','爱')() // 12你
fn._bind(null, '我')('爱') // 12她
js实现bind简单易懂
最新推荐文章于 2022-08-02 17:26:36 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)