-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession4.js
71 lines (63 loc) · 1.48 KB
/
session4.js
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
62
63
64
65
66
67
68
69
70
71
//THIS
function bike() {
console.log(this.name);
}
var name = "Ninja";
var obj1 = {
name: "Pulsar",
bike: bike
};
var obj2 = {
name: "Gixxer",
bike: bike
};
bike(); // "Ninja"
obj1.bike(); // "Pulsar"
obj2.bike(); // "Gixxer"
function bike() {
var name = "Ninja";
this.name = "NINJA";
this.maker = "Kawasaki";
console.log(this.name + " " + maker); // undefined Bajaj
}
var name = "Pulsar";
var maker = "Bajaj";
obj = new bike();
console.log(obj.maker); // "Kawasaki"
//Functions
//OOP in ES5
//Construct0r Function
function Person(firstName, lastName, dob) {
this.firstName = firstName;
this.lastName = lastName;
this.dob = new Date(dob);
this.getFullName = function () {
return `${this.firstName} ${this.lastName}`;
}
// this.getBirthYear = function()
// {
// return this.dob.getFullYear();
// }
}
//OOPS in ES6
//syntex suger //orgnaized
//Class
class Persons {
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}`;
}
}
const person11 = new Persons('Adarsh', 'Pawar', '06-08-1996');
const person22 = new Persons('Wanda', 'Kaur', '02-01-1994');
console.log(person22);
console.log(person22.dob.getDate);
console.log(person11.getBirthYear());
console.log(person22.getFullName());