function foo(name){
console.log('this.a:',this.a)
this.name = name
}
foo.prototype.sex = 'man';
const bar = { a: 'bar' }
Function.prototype.bind = function(){
const self = this
const args = [...arguments]
const ctx = args.shift()
function fBound() {
const otherArgs = [...arguments]
return self.apply(this instanceof fBound ? this : ctx, args.concat(otherArgs))
}
fBound.prototype = this.prototype
return fBound
}
const bindFoo = foo.bind(bar, 1, 2)
const newBind = new bindFoo('bind')
console.log(newBind.name)
console.log(newBind.sex)
console