File tree Expand file tree Collapse file tree 1 file changed +30
-2
lines changed
Roadmap/24 - DECORADORES/javascript Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change 9
9
*/
10
10
11
11
/*
12
+
12
13
Esta es la propuesta de decoradores de Javascript, aún en stage 3
13
14
function logger(value, context) {
14
15
console.log(value, context);
@@ -27,7 +28,6 @@ class Persona {
27
28
*/
28
29
29
30
// Implementación del Patrón Decorador sin sintaxis de decorador
30
-
31
31
function logger ( metodo ) {
32
32
33
33
return function ( ...arg ) {
@@ -52,4 +52,32 @@ class Persona {
52
52
p1 = new Persona ( ) ;
53
53
54
54
p1 . getAltura = logger ( p1 . getAltura ) ;
55
- p1 . getAltura ( ) ;
55
+ p1 . getAltura ( ) ;
56
+
57
+
58
+ console . log ( '---------------------------DIFICULTAD EXTRA------------------------' ) ;
59
+
60
+ let numLlamadas = 0 ;
61
+
62
+ const contador = ( metodo ) => {
63
+
64
+ return function ( ...arg ) {
65
+
66
+ numLlamadas ++ ;
67
+ metodo . apply ( this , ...arg ) ;
68
+ }
69
+ }
70
+
71
+ let antonioRecio = ( ) => {
72
+ console . log ( 'Antonio Recio, mayorista, no limpio pescado' ) ;
73
+ }
74
+
75
+ antonioRecio = contador ( antonioRecio ) ;
76
+
77
+ let i = 0 ;
78
+ while ( i < Math . floor ( Math . random ( ) * 10 ) + 1 ) {
79
+ antonioRecio ( ) ;
80
+ i ++ ;
81
+ }
82
+
83
+ console . log ( `La función ha sido llamada ${ numLlamadas } veces` ) ;
You can’t perform that action at this time.
0 commit comments