class Flower {}
// 源对象
class Jack {
constructor (target) {
console.log('1')
this.target = target;
//這個target 等於 proxyObj
}
sendFlower (target) {
console.log('2')
const flower = new Flower();
this.target.receiveFlower(flower)
}
}
// 目标对象
class Rose {
receiveFlower (flower) {
console.log('3')
console.log('收到花: ' + flower)
}
}
// 代理对象
class ProxyObj {
constructor () {
console.log('4')
this.target = new Rose();
}
receiveFlower (flower) {
console.log('5')
this.sendFlower(flower)
}
sendFlower (flower) {
console.log('6')
this.target.receiveFlower(flower)
}
}
const proxyObj = new ProxyObj();
const jack = new Jack(proxyObj);
jack.sendFlower(proxyObj);