js手動実現ビッド
593 ワード
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)