new MyPromise(function(resolve,reject){
reject()
});
class MyPromise{
constructor(fn){
fn(this.resolve,this.reject)
}
resolve(){
}
reject(){
}
}
class Person{
constructor(per){
per(this.teach,this.say)
}
teach(){
console.log('上课')
}
say(){
console.log('讲课')
}
}
new Person(function(teach,say){
teach()
say()
})
构造函数接收一个函数per,将方法teach()和say()的引用传递给per,所以per可以使用这两个方法。