-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgNine.js
More file actions
61 lines (57 loc) · 2.2 KB
/
pgNine.js
File metadata and controls
61 lines (57 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const titleNine = () => "///////////// THIS IS PAGE NINE /////////////";
console.log(titleNine());
/////// OBJECT ORIENTED PROGRAMMING
/////// constructor function - all constructor functions need to start with a capital.
function Soldier(firstName, lastName, dob) {
// setting properties to the oject. ex .this
this.firstName = firstName;
this.lastName = lastName;
// this.dob = dob;
// adding new Date(dob) date method you can pull more information from the date object.
this.dob = new Date(dob);
/// adding methods(functions) to this person object. ex .getBirthYear .getFullName
this.getBirthYear = function () {
return this.dob.getFullYear();
};
this.getFullName = function () {
return `${this.firstName} ${this.lastName}`;
};
}
/// prototypes
Soldier.prototype.getBrithYear = function () {
return this.dob.getFullYear();
};
Soldier.prototype.getFullName = function () {
return `${this.firstName} ${this.lastName}`;
};
//// es6 classes aka syntatic sugar. this class does the same thing as the code above. just a lot cleaner.
// developers from other backgrounds can transition into JavaScript easier with this new pizzazz. "jazz hands"
// class Soldier {
// constructor(firstName, lastName, dob) {
// this.firstName = firstName;
// this.lastName = lastName;
// this.dob = new Date(dob);
// }
// getBirthYear() {
// return this.dob.getFullYear();
// }
// getFullName() {
// return `${this.firstName} ${this.lastName}`;
// }
// }
///////////////////////// es6 class
// Instantiate object
// creating as many different soldiers based off of our constructor function soldier object.
const soldier1 = new Soldier("Carlos", "Concepcion", "4-4-1960");
const soldier2 = new Soldier("Elsa", "Concepcion", "11-17-1940");
// console.log(soldier1);
// console.log(soldier1.dob.getFullYear());
// console.log(soldier1.dob.getTime()); // playin around with the new Date methods.
// console.log(soldier2); // reg return with new Date(dob)
/// calling methods in the constructor function object.
console.log(soldier1.getBirthYear());
console.log(soldier1.getFullName());
console.log(soldier1);
console.log(soldier2.getBirthYear());
console.log(soldier2.getFullName());
console.log(soldier2);