File tree Expand file tree Collapse file tree 1 file changed +26
-6
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +26
-6
lines changed
Original file line number Diff line number Diff line change 1
- class Person {
2
- constructor ( firstAndLast ) {
3
- this . getFirstName = ( ) => firstAndLast . slice ( 0 , firstAndLast . indexOf ( " " ) ) ;
4
- this . getLastName = ( ) => firstAndLast . slice ( firstAndLast . indexOf ( " " ) + 1 ) ;
5
- this . getFullName = ( ) => firstAndLast ;
1
+ function Person ( firstAndLast ) {
2
+ let names = {
3
+ firstName : firstAndLast . slice ( 0 , firstAndLast . indexOf ( " " ) ) ,
4
+ lastName : firstAndLast . slice ( firstAndLast . indexOf ( " " ) + 1 )
5
+
6
6
}
7
+
8
+ this . getFirstName = ( ) => names . firstName ;
9
+ this . getLastName = ( ) => names . lastName ;
10
+ this . getFullName = ( ) => `${ names . firstName } ${ names . lastName } ` ;
11
+
12
+ this . setFirstName = ( firstName ) => {
13
+ names . firstName = firstName ;
14
+ }
15
+ this . setLastName = ( lastName ) => {
16
+ names . lastName = lastName ;
17
+ }
18
+
19
+ this . setFullName = ( firstAndLast ) => {
20
+ names . firstName = firstAndLast . slice ( 0 , firstAndLast . indexOf ( " " ) ) ;
21
+ names . lastName = firstAndLast . slice ( firstAndLast . indexOf ( " " ) + 1 ) ;
22
+ }
23
+
7
24
}
25
+
8
26
9
27
const bob = new Person ( 'Bob Ross' ) ;
10
28
console . log ( bob . getFirstName ( ) ) ;
11
- console . log ( bob . getFullName ( ) ) ;
29
+ bob . setFirstName ( "Rass" ) ;
30
+ console . log ( bob . getFirstName ( ) ) ;
31
+ console . log ( Object . keys ( bob ) . length ) ;
You can’t perform that action at this time.
0 commit comments