Skip to content

Commit

Permalink
mouredev#24 - JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
RicJDev committed Jun 14, 2024
1 parent 3e6b6df commit db7f739
Showing 1 changed file with 36 additions and 38 deletions.
74 changes: 36 additions & 38 deletions Roadmap/24 - DECORADORES/javascript/RicJDev.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
//EJERCICIO
class BasicPizza {
constructor(size) {
this.price = this.pricesList[size];
}

toppings = ['salsa', 'mozzarella', 'pepperoni'];

//Precios en dólares, jajs
pricesList = {
small: '$5.00',
medium: '$9.00',
large: '$12.00',
extralarge: '$16.00',
function steveDecorator(fun) {
return function (...arg) {
let result = fun(...arg);
console.log('Soy Steve, el decorador');
return result;
};
}

getPrice() {
console.log(this.price);
}
function greeting(name) {
console.log(`\nHola, ${name}`);
}

class HawaianPizza extends BasicPizza {
constructor(size) {
super(size);
this.toppings.push('jamón', 'piña');
this.price = this.pricesList[size];
}

pricesList = {
small: '$6.70',
medium: '$10.50',
large: '$13.50',
extralarge: '$16.30',
greeting('Jeff');

greeting = steveDecorator(greeting);

greeting('Gerard');

//EXTRA
function counterDecorator(fun) {
let count = 0;

return function (...arg) {
count++;
result = fun(...arg);
console.log(`Conteo de llamadas de ${fun.name}(): ${count}`);
return result;
};
}

class PizzaDecorator extends BasicPizza {
constructor(pizza) {
super(pizza.size, pizza.toppings);
this.pizza = pizza;
}
function addTwoNumbers(a, b) {
console.log(`\nEl resultado de sumar ${a} y ${b} es ${a + b}`);
}

addTwoNumbers = counterDecorator(addTwoNumbers);

addTwoNumbers(10, 23);
addTwoNumbers(14, 3);

getPrice() {
this.pizza.getPrice();
}
function square(a) {
console.log(`\nEl cuadrado de ${a} es igual a ${a * a}`);
}

let pizza1 = new HawaianPizza('small');
square = counterDecorator(square);

pizza1.getPrice();
square(9);
square(5);

0 comments on commit db7f739

Please sign in to comment.