Skip to content

Commit 85edd8b

Browse files
committed
Constructor Property
1 parent 2e2c237 commit 85edd8b

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

app.js

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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
54

65
/* Constructor Functions */
76
function Person(firstName, lastName) {
@@ -12,33 +11,22 @@ function Person(firstName, lastName) {
1211
`Hello, my name is ${this.firstName} ${this.lastName} and I love React`
1312
);
1413
};
15-
console.log(this);
1614
}
1715

18-
const john = new Person("john", "aderson");
19-
john.fullName();
16+
const john = new Person("john", "anderson");
17+
console.log(john.constructor);
2018

21-
const bob = new Person("bob", "jordon");
22-
bob.fullName();
19+
const bob = new Person("bob", "anderson");
20+
console.log(bob.constructor);
2321

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);
3624

37-
// const john = createPerson("john", "anderson");
38-
// john.fullName();
25+
const array = [];
26+
console.log(array.constructor);
3927

40-
// const bob = createPerson("bob", "jordan");
41-
// bob.fullName();
28+
const sayHi = function () {};
29+
console.log(sayHi.constructor);
4230

43-
// const susy = createPerson("susy", "apple");
44-
// susy.fullName();
31+
const susy = new john.constructor("susy", "anderson");
32+
susy.fullName();

0 commit comments

Comments
 (0)