forked from bittu1040/JavaScript-Coding-and-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOPS-practice.js
More file actions
105 lines (63 loc) · 1.67 KB
/
OOPS-practice.js
File metadata and controls
105 lines (63 loc) · 1.67 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
getDetails() {
return this.name + " " + this.age;
}
}
let person1 = new Person("bittu", 27);
console.log(person1)
function Car(name, color){
this.name= name;
this.color= color;
}
Car.prototype.getDetails= function(){
return this.name;
}
let car1= new Car("maruti", "red");
console.log(car1);
function getDetails1(){
return "some thing"
}
function State(name, country){
this.name= name;
this.country= country;
}
let karnataka= new State("KA", "india");
console.log(karnataka);
// inheritance
// object1 --- all property-- accesible in obj2
// constrctor function - all property -- i want in constructor function 2
// class 1 propety --- to another class
let obj1= {name:"bittu", age: 27}
let obj2= {city: "BLR"}
// way 1
//obj2.__proto__= obj1
// way 2
// let obj2= Object.create(obj1, {city: {value: "blr", }, prop1: {value: "prppp"}})
console.log(obj2);
// constructor function inheritance
function Parent(name, age, house){
this.name= name;
this.age= age;
this.house= house
}
Parent.prototype.getDetails= function(){
return this.name+" " + this.age;
}
let parent1= new Parent("bittu", 27)
function Child(name, age, schoolname){
Parent.call(this, name, age)
this.schoolname= schoolname;
}
Child.prototype= Object.create(Parent.prototype)
Child.prototype.getSchoolDetails= function(){
return this.name+ " " + this.schoolname;
}
let child1= new Child("ravi", 12, "avm")
console.log(child1.getDetails())
console.log(child1.getSchoolDetails())
console.log(parent1.getDetails())
console.log(child1)