File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- const adder = initial => ( {
3
+ const adder = ( initial = 0 ) => ( {
4
4
value : initial ,
5
+ steps : [ initial ] ,
5
6
add ( value ) {
7
+ this . steps . push ( value ) ;
6
8
this . value += value ;
7
9
return this ;
8
10
}
9
11
} ) ;
10
12
11
13
const Adder = class {
12
- constructor ( initial ) {
14
+ constructor ( initial = 0 ) {
15
+ this . steps = [ initial ] ;
13
16
this . value = initial ;
14
17
}
15
18
add ( value ) {
19
+ this . steps . push ( value ) ;
16
20
this . value += value ;
17
21
return this ;
18
22
}
@@ -21,11 +25,15 @@ const Adder = class {
21
25
// Usage
22
26
23
27
{
24
- const v = new Adder ( 3 ) . add ( - 9 ) . add ( 12 ) ;
25
- console . log ( v ) ;
28
+ const { value, steps } = new Adder ( 5 ) . add ( - 8 ) . add ( 11 ) ;
29
+ console . log ( value ) ;
30
+ const [ a , b , c ] = steps ;
31
+ console . log ( a , b , c ) ;
26
32
}
27
33
28
34
{
29
- const v = adder ( 3 ) . add ( - 9 ) . add ( 12 ) ;
30
- console . log ( v ) ;
35
+ const { value, steps } = adder ( 5 ) . add ( - 8 ) . add ( 11 ) ;
36
+ console . log ( value ) ;
37
+ const [ a , b , c ] = steps ;
38
+ console . log ( a , b , c ) ;
31
39
}
Original file line number Diff line number Diff line change @@ -26,3 +26,5 @@ const PointEx = serializable(movable(Point));
26
26
const point1 = new PointEx ( 10 , 20 ) ;
27
27
point1 . move ( 5 , - 2 ) ;
28
28
console . log ( point1 . toString ( ) ) ;
29
+ const { x, y } = point1 ;
30
+ console . log ( x , y ) ;
You can’t perform that action at this time.
0 commit comments