Guest User

Untitled

a guest
Feb 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. // 定义一个基础命令
  2. class Love {
  3. express() {
  4. cosnole.log("to be brave");
  5. }
  6. }
  7.  
  8. // 定义一个命令对象
  9. class Valentine extends Love {
  10. expressToMysun() {
  11. console.log("i wanna accompany with you forever");
  12. }
  13. express() {
  14. this.expressToMysun();
  15. }
  16. }
  17.  
  18. const me = new Valentine();
  19. // 接受者接收这个命令对象
  20. class Reciver {
  21. constructor(girl) {
  22. this.girl = girl;
  23. }
  24. setCommand(person, commandExpress) {
  25. this.girl[person] = commandExpress;
  26. }
  27. getLove(person) {
  28. this.girl[person].express();
  29. }
  30. }
  31.  
  32. let sun = [];
  33. const girlFriend = new Reciver(sun);
  34. girlFriend.setCommand(0, me);
  35. girlFriend.getLove(0);
Add Comment
Please, Sign In to add comment