Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. class Food {
  2. constructor(options) {
  3. this.type = options.type
  4. }
  5. eat() {
  6. return `I'm eating ${this.type}`
  7. }
  8. }
  9.  
  10.  
  11. class Pasta extends Food {
  12. constructor(options) {
  13. super(options)
  14. }
  15. }
  16.  
  17. class Hamburger extends Food {
  18. constructor(options) {
  19. super(options)
  20. }
  21. }
  22.  
  23. class Salad extends Food {
  24. constructor(options) {
  25. super(options)
  26. }
  27. }
  28.  
  29.  
  30. const Restaurant = {
  31. prapare: (options) => {
  32. const { type } = options;
  33.  
  34. if (type == 'Pasta') {
  35. return new Pasta(options)
  36. }
  37. if (type == 'Hamburger') {
  38. return new Hamburger(options)
  39. }
  40. if (type == 'Salad') {
  41. return new Salad(options)
  42. }
  43. }
  44. }
  45.  
  46.  
  47. const pasta = Restaurant.prapare({ type: 'Pasta' })
  48. const hamburger = Restaurant.prapare({ type: 'Hamburger' })
  49. const salad = Restaurant.prapare({ type: 'Salad' })
  50.  
  51. console.log(pasta.eat())
  52. console.log(hamburger.eat())
  53. console.log(salad.eat())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement