当前位置: 移动技术网 > IT编程>网页制作>CSS > js手动实现bind教程

js手动实现bind教程

2019年04月19日  | 移动技术网IT编程  | 我要评论
function.prototype.bind=function(obj){ var arg=array.prototype.slice.call(arguments
function.prototype.bind=function(obj){
    var arg=array.prototype.slice.call(arguments,1);
    var context=this;
    var bound=function(){
      arg=arg.concat(array.prototype.slice.call(arguments));
      return context.apply(obj,arg);
    }
    var f=function(){}
    f.prototype=context.prototype;
    bound.prototype=new f();
    return bound;
}

function read(name, time, book) {
    console.log(`${name} is reading ${book} at ${time}`)
}

var tomread = read.bind(this, 'tom', 'morning')
tomread('<万历十五年>')
console.log(tomread.bind)

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网