Function.prototype.myBind=function(context){
if(typeof this !=="function"){
throw new TypeError("this is not a function");
}
context = context || window;
const _this = this;
const args = Array.from(arguments).slice(1);
return function F(){
if(this instanceof F){
return new _this(...args);
}else{
return _this.apply(context,...args);
}
}
}
function print(name,age){
if(name&&age){
this.name = name;
this.age = age;
}
console.log(`I am ${this.name},I am ${this.age} years old!`);
}
let obj = {
name:"ax",
age:20
}
let f = print.myBind(obj)();
let test = new print("kime",19);
console