Skip to content

Commit 6030674

Browse files
updated
1 parent c6fd42f commit 6030674

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
let fName = "Sujit "
22
let lName = "Tomar"
33

4+
let vegetable = ["Potato", "Capsicum", "Lady Finger", "Onion"]
5+
6+
let vegetablePrice = {
7+
patato : 40,
8+
Capsicum : 50,
9+
LadyFinger : 40,
10+
Onion : 60,
11+
12+
getPrice: function(){
13+
console.log(`Capsicum Price is ${this.Capsicum}`)
14+
}
15+
}
16+
17+
18+
// I want to create selfMade Method for Object because everything in JS are object so if i give to power in object than my method are available in everywhere like array, function, object, string everywhere.
19+
20+
// i create a self made method sujittomar
21+
Object.prototype.sujittomar = function(){
22+
console.log("Sujit Tomar Available Here");
23+
}
24+
25+
26+
// Now i can use the method
27+
vegetablePrice.sujittomar() // Sujit Tomar Available Here
28+
fName.sujittomar() // Sujit Tomar Available Here
29+
vegetable.sujittomar() // Sujit Tomar Available Here
30+
31+
32+
// Now i can give a self made function for array
33+
Array.prototype.tomar = ()=>{
34+
console.log("Tomar is a title of sujit");
35+
}
36+
37+
// now i can use the array self made method
38+
vegetable.tomar() // Tomar is a title of sujit
39+
vegetablePrice.tomar() // Error here because it is object but this method onle give to array

0 commit comments

Comments
 (0)