1
- // Blue Print
2
- // Factory Functions and Constructor Functions
3
- // Constructor Functions
4
- // new - creates new object, points to it, omit return
1
+ // All Objects in Javascript have access to constructor property that returns a constructor function that created it.
2
+ // built in constructor functions
3
+ // arrays and functions are objects in javascript
5
4
6
5
/* Constructor Functions */
7
6
function Person ( firstName , lastName ) {
@@ -12,33 +11,22 @@ function Person(firstName, lastName) {
12
11
`Hello, my name is ${ this . firstName } ${ this . lastName } and I love React`
13
12
) ;
14
13
} ;
15
- console . log ( this ) ;
16
14
}
17
15
18
- const john = new Person ( "john" , "aderson " ) ;
19
- john . fullName ( ) ;
16
+ const john = new Person ( "john" , "anderson " ) ;
17
+ console . log ( john . constructor ) ;
20
18
21
- const bob = new Person ( "bob" , "jordon " ) ;
22
- bob . fullName ( ) ;
19
+ const bob = new Person ( "bob" , "anderson " ) ;
20
+ console . log ( bob . constructor ) ;
23
21
24
- /* Factory Functions */
25
- function createPerson ( firstName , lastName ) {
26
- return {
27
- firstName : firstName ,
28
- lastName : lastName ,
29
- fullName : function ( ) {
30
- console . log (
31
- `Hello, my name is ${ this . firstName } ${ this . lastName } and I love JS`
32
- ) ;
33
- } ,
34
- } ;
35
- }
22
+ const object = { } ;
23
+ console . log ( object . constructor ) ;
36
24
37
- // const john = createPerson("john", "anderson") ;
38
- // john.fullName( );
25
+ const array = [ ] ;
26
+ console . log ( array . constructor ) ;
39
27
40
- // const bob = createPerson("bob", "jordan") ;
41
- // bob.fullName( );
28
+ const sayHi = function ( ) { } ;
29
+ console . log ( sayHi . constructor ) ;
42
30
43
- // const susy = createPerson ("susy", "apple ");
44
- // susy.fullName();
31
+ const susy = new john . constructor ( "susy" , "anderson " ) ;
32
+ susy . fullName ( ) ;
0 commit comments