利用js原声实现一个bind函数。
Function.prototype.my_bind = function(){
const _this = this; //获取当前函数本身
const args = Array.prototype.slice.call(arguments); //将累数组类型arguments转化成一个数组.
const context = args[0]; //参数第一项为需要绑定的对象
const _args = args.slice(1); //参数剩下的项为参数数组
return function(){
//合并第一段和二段的参数
_this.apply(context,Array.prototype.concat(_args,Array.prototype.slice.call(arguments)));
}
}