Skip to content

Commit 4985572

Browse files
updated
1 parent 6030674 commit 4985572

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

25_Revision/19_oops_and_classes/03_prototype.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ Array.prototype.tomar = ()=>{
3636

3737
// now i can use the array self made method
3838
vegetable.tomar() // Tomar is a title of sujit
39-
vegetablePrice.tomar() // Error here because it is object but this method onle give to array
39+
/* vegetablePrice.tomar() // Error here because it is object but this method onle give to array */
40+
41+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// inheritance
2+
3+
let carBasic = {
4+
start : true,
5+
break : true,
6+
seat : true,
7+
}
8+
9+
let carDieselFuel = {
10+
fuel : "Diesel"
11+
}
12+
13+
let carPetrolFuel = {
14+
fuel : "Petrol"
15+
}
16+
17+
let carInsurence = {
18+
insurence : true
19+
}
20+
21+
// Now i want to carBasic Method and Fuel type method in below car because car have need for this so
22+
// it is old syntax __proto__
23+
let mercedesCar = {
24+
color : "Black",
25+
airBag : "4",
26+
27+
__proto__ : carBasic,
28+
__proto__: carDieselFuel
29+
}
30+
31+
let rangeRover = {
32+
color : "white",
33+
airBag : "4"
34+
}
35+
36+
rangeRover.__proto__ = carBasic
37+
rangeRover.__proto__ = carPetrolFuel
38+
39+
// modern syntax
40+
Object.setPrototypeOf(rangeRover, carInsurence)
41+
Object.setPrototypeOf(mercedesCar, carInsurence)
42+
43+

0 commit comments

Comments
 (0)