1
1
// Blue Print
2
2
// Factory Functions and Constructor Functions
3
- // Factory Functions
3
+ // Constructor Functions
4
+ // new - creates new object, points to it, omit return
4
5
5
- // const john = {
6
- // firstName: "john",
7
- // lastName: "anderson",
8
- // fullName: function () {
9
- // // console.log(this);
10
- // console.log(
11
- // `Hello, my name is ${this.firstName} ${this.lastName} and I love JS`
12
- // );
13
- // },
14
- // };
6
+ /* Constructor Functions */
7
+ function Person ( firstName , lastName ) {
8
+ this . firstName = firstName ;
9
+ this . lastName = lastName ;
10
+ this . fullName = function ( ) {
11
+ console . log (
12
+ `Hello, my name is ${ this . firstName } ${ this . lastName } and I love React`
13
+ ) ;
14
+ } ;
15
+ console . log ( this ) ;
16
+ }
15
17
16
- // const bob = {
17
- // firstName: "bob",
18
- // lastName: "anderson",
19
- // fullName: function () {
20
- // // console.log(this);
21
- // console.log(`Hello, my name is ${this.firstName} ${this.lastName}`);
22
- // },
23
- // };
18
+ const john = new Person ( "john" , "aderson" ) ;
19
+ john . fullName ( ) ;
24
20
25
- // john.fullName( );
26
- // bob.fullName();
21
+ const bob = new Person ( "bob" , "jordon" ) ;
22
+ bob . fullName ( ) ;
27
23
24
+ /* Factory Functions */
28
25
function createPerson ( firstName , lastName ) {
29
26
return {
30
27
firstName : firstName ,
@@ -37,11 +34,11 @@ function createPerson(firstName, lastName) {
37
34
} ;
38
35
}
39
36
40
- const john = createPerson ( "john" , "anderson" ) ;
41
- john . fullName ( ) ;
37
+ // const john = createPerson("john", "anderson");
38
+ // john.fullName();
42
39
43
- const bob = createPerson ( "bob" , "jordan" ) ;
44
- bob . fullName ( ) ;
40
+ // const bob = createPerson("bob", "jordan");
41
+ // bob.fullName();
45
42
46
- const susy = createPerson ( "susy" , "apple" ) ;
47
- susy . fullName ( ) ;
43
+ // const susy = createPerson("susy", "apple");
44
+ // susy.fullName();
0 commit comments