11// Blue Print
22// Factory Functions and Constructor Functions
3- // Factory Functions
3+ // Constructor Functions
4+ // new - creates new object, points to it, omit return
45
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+ }
1517
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 ( ) ;
2420
25- // john.fullName( );
26- // bob.fullName();
21+ const bob = new Person ( "bob" , "jordon" ) ;
22+ bob . fullName ( ) ;
2723
24+ /* Factory Functions */
2825function createPerson ( firstName , lastName ) {
2926 return {
3027 firstName : firstName ,
@@ -37,11 +34,11 @@ function createPerson(firstName, lastName) {
3734 } ;
3835}
3936
40- const john = createPerson ( "john" , "anderson" ) ;
41- john . fullName ( ) ;
37+ // const john = createPerson("john", "anderson");
38+ // john.fullName();
4239
43- const bob = createPerson ( "bob" , "jordan" ) ;
44- bob . fullName ( ) ;
40+ // const bob = createPerson("bob", "jordan");
41+ // bob.fullName();
4542
46- const susy = createPerson ( "susy" , "apple" ) ;
47- susy . fullName ( ) ;
43+ // const susy = createPerson("susy", "apple");
44+ // susy.fullName();
0 commit comments