//代码实现call方法
Function.prototype.myCall=function(obj,...args){
obj._fn_ = this
obj._fn_(...args)
delete obj._fn_
}
//代码实现apply方法
Function.prototype.myApply=function(obj,args){
var argms = []
for(let i=0;i<args.length;i++){
argms.push(args[i])
}
return this.myCall(obj,...argms)
}
//代码实现bind方法
Function.prototype.myBind=function(obj,...arg2){
return (...arg3) =>{
return this.myApply(obj, arg2.concat([...arg3]))
}
}
function Person(name){
this.name=name
}
Person.prototype.sayIt=function(){
console.log(this.name, ...arguments)
}
//组合继承
function Girl(name){
Person.call(this, name)
}
Girl.prototype = new Person()
console.log('compile')
var roc = new Person('roc')
var girl = new Girl('Mary')
var bindGirl = roc.sayIt.myBind(girl)
console.log(bindGirl('hello','roc'))
console