Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 定义一个基础命令
- class Love {
- express() {
- cosnole.log("to be brave");
- }
- }
- // 定义一个命令对象
- class Valentine extends Love {
- expressToMysun() {
- console.log("i wanna accompany with you forever");
- }
- express() {
- this.expressToMysun();
- }
- }
- const me = new Valentine();
- // 接受者接收这个命令对象
- class Reciver {
- constructor(girl) {
- this.girl = girl;
- }
- setCommand(person, commandExpress) {
- this.girl[person] = commandExpress;
- }
- getLove(person) {
- this.girl[person].express();
- }
- }
- let sun = [];
- const girlFriend = new Reciver(sun);
- girlFriend.setCommand(0, me);
- girlFriend.getLove(0);
Add Comment
Please, Sign In to add comment