Skip to content

Commit 84adf84

Browse files
authored
Merge pull request mouredev#4232 from AChapeton/main
#24 - Typescript & Javascript
2 parents cddab39 + ab3377a commit 84adf84

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class BasicMath {
2+
sumar(a, b){
3+
return a + b
4+
}
5+
6+
restar(a, b){
7+
return a - b
8+
}
9+
10+
multiplicar(a, b){
11+
return a * b
12+
}
13+
14+
dividir(a, b){
15+
if (b === 0) {
16+
throw new Error('Division by zero is not allowed')
17+
}
18+
return a / b
19+
}
20+
}
21+
22+
const mathDecorator = (fun) => {
23+
return function(...args){
24+
console.log(`Llamando a la funcion ${fun.name} con argumentos`, args)
25+
return fun.apply(this, args)
26+
}
27+
}
28+
29+
BasicMath.prototype.sumar = mathDecorator(BasicMath.prototype.sumar)
30+
BasicMath.prototype.restar = mathDecorator(BasicMath.prototype.restar)
31+
BasicMath.prototype.multiplicar = mathDecorator(BasicMath.prototype.multiplicar)
32+
BasicMath.prototype.dividir = mathDecorator(BasicMath.prototype.dividir)
33+
34+
const test = new BasicMath()
35+
36+
console.log(test.sumar(2, 3))
37+
console.log(test.restar(5, 3))
38+
console.log(test.multiplicar(4, 3))
39+
console.log(test.dividir(10, 2))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class BasicMath {
2+
sumar(a: number, b: number){
3+
return a + b
4+
}
5+
6+
restar(a: number, b: number){
7+
return a - b
8+
}
9+
10+
multiplicar(a: number, b: number){
11+
return a * b
12+
}
13+
14+
dividir(a: number, b: number){
15+
if (b === 0) {
16+
throw new Error('No se puede dividir entre 0')
17+
}
18+
return a / b
19+
}
20+
}
21+
22+
const mathDecorator = (fun) => {
23+
return function(...args){
24+
console.log(`Llamando a la funcion ${fun.name} con argumentos`, args)
25+
return fun.apply(this, args)
26+
}
27+
}
28+
29+
BasicMath.prototype.sumar = mathDecorator(BasicMath.prototype.sumar)
30+
BasicMath.prototype.restar = mathDecorator(BasicMath.prototype.restar)
31+
BasicMath.prototype.multiplicar = mathDecorator(BasicMath.prototype.multiplicar)
32+
BasicMath.prototype.dividir = mathDecorator(BasicMath.prototype.dividir)
33+
34+
const test = new BasicMath()
35+
36+
console.log(test.sumar(2, 3))
37+
console.log(test.restar(5, 3))
38+
console.log(test.multiplicar(4, 3))
39+
console.log(test.dividir(10, 2))

0 commit comments

Comments
 (0)