自己实现一个bind函数
作者:
前端小旋风 | 来源:发表于
2020-07-20 16:11 被阅读0次Function.prototype.myBind = function (){
if(typeof this !== 'function') throw new TypeError('@');
var fn_self = this,
fn_args = Array.prototype.slice.call(arguments,1);
var fn_empty = function (){}
var fn = function (){
return fn_self.apply(this instanceof fn ? this : arguments[0],fn_args.concat(Array.prototype.slice.call(arguments)))
}
if(this.prototype){
fn_empty.prototype = this.prototype;
}
fn.prototype = new fn_empty();
return fn;
}
本文标题:自己实现一个bind函数
本文链接:https://www.haomeiwen.com/subject/mbrykktx.html
网友评论