-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototype.js
More file actions
71 lines (48 loc) · 1.67 KB
/
Copy pathPrototype.js
File metadata and controls
71 lines (48 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
// let myName = "sandeep "
// console.log(myName.truelength);
let myHero = ["thor", "spiderman"]
let heroPower = {
thor: "hammer",
spiderman: "sling",
getSpiderPower: function() {
console.log(`Spidy power is $(this.spiderman)`)
}
}
Object.prototype.sandeep = function() { // create own method which is accessably to all (function, object, array)
console.log(`sandeep is present in all objects`)
}
Array.prototype.heySandeep = function() { // create own method which is accesably only for array
console.log(`sandeep say hello`)
}
//heroPower.sandeep()
// myHero.sandeep()
// myHero.heySandeep()
// heroPower.heySandeep()
// inheritance
const user = {
name: "chai",
email: "[email protected]"
}
const teacher = {
makeVideo: true,
}
const teachingSupport = {
isAbailable: false,
}
const TASupport = {
makeAssignment: 'Js assignment',
fullTime: true,
__proto__: teachingSupport
}
teacher.__proto__ = user;
// modern syntax
Object.setPrototypeOf(teachingSupport, teacher)
// console.log(teachingSupport.makeVideo)
let anotherUsername = "chaiaurcode "
String.prototype.trueLength = function() { // creating own method which trim the space and show only true lenth of the string
// console.log(`${this}`)
console.log(`True length is: ${this.trim().length}`); // jis ne call kiya wahi this h
}
anotherUsername.trueLength()
"sandeep ".trueLength()
"india ".trueLength()