Function.prototype.bind = function(){
let context = [].shift.call(arguments)
let self = this;
let args = arguments;
return function () {
return self.apply(context,[...args,...arguments])
}
}
let temp = Array.prototype.concat.bind([1,3,5],7,8,9)
console.log(temp(10,12));
【JS】手写bind
最新推荐文章于 2025-05-09 11:30:40 发布
本文深入探讨了JavaScript中Function.prototype.bind方法的实现原理,通过一个自定义实现来展示其工作过程。示例展示了如何使用bind结合Array.prototype.concat方法创建一个组合函数,并在实际应用中打印出预期结果。这有助于理解JavaScript函数上下文和参数操作。
1214

被折叠的 条评论
为什么被折叠?



