Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Food {
- constructor(options) {
- this.type = options.type
- }
- eat() {
- return `I'm eating ${this.type}`
- }
- }
- class Pasta extends Food {
- constructor(options) {
- super(options)
- }
- }
- class Hamburger extends Food {
- constructor(options) {
- super(options)
- }
- }
- class Salad extends Food {
- constructor(options) {
- super(options)
- }
- }
- const Restaurant = {
- prapare: (options) => {
- const { type } = options;
- if (type == 'Pasta') {
- return new Pasta(options)
- }
- if (type == 'Hamburger') {
- return new Hamburger(options)
- }
- if (type == 'Salad') {
- return new Salad(options)
- }
- }
- }
- const pasta = Restaurant.prapare({ type: 'Pasta' })
- const hamburger = Restaurant.prapare({ type: 'Hamburger' })
- const salad = Restaurant.prapare({ type: 'Salad' })
- console.log(pasta.eat())
- console.log(hamburger.eat())
- console.log(salad.eat())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement