-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.html
More file actions
109 lines (95 loc) · 2.93 KB
/
object.html
File metadata and controls
109 lines (95 loc) · 2.93 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="background-color: black;">
<script>
function multipleBy5(num) {
return num * 5;
}
multipleBy5.power = 2;
// console.log(multipleBy5(5));
// console.log(multipleBy5.power);
// console.log(multipleBy5.prototype); // function is also an object
// ***************************
function createUser(username, score) {
this.username = username // .this set the correct context and store in new object
this.score = score
}
createUser.prototype.increament = function () {
this.score++;
}
createUser.prototype.printMe = function () {
// console.log(`price is ${this.score}`);
}
const chai = new createUser('chai', 25)
const tea = new createUser('tea', 250)
chai.printMe()
tea.printMe()
// *********************** prototype ********************
// let myName = 'shfia '
// let meJs = 'JavaScript '
// console.log(myName.trueLength);
// ***********************
let friends = ("Shfia", "LAiba","kainat" , "Mehk")
let myHeros= ['Thore','Spiderman']
let heroPower={
thor: 'hameer',
spiderMan : 'sling',
// Method
getSpiderPwer:function(){
console.log(`spiderpower is ${this.spiderMan}`);
}
} // we can create our own functions and also combine them in other functions or method
Object.prototype.shifa= function(){
console.log(`Shfia is present in all objects`);
}
Array.prototype.arryShifa= function(){
console.log("Shfia says Hello");
}
Object.prototype.objShfia = function(){
console.log("hello world");
}
// friends.shifa();
// heroPower .shifa();
// myHeros.shifa()
// myHeros.arryShifa()
// heroPower.objShfia()
// friends.objShfia()
// ************ Inheritnce ************
const user={
name : "cai",
email : 'chai@google.com'
}
const Teacher = {
makeVideo : true
}
const TeacherSupport = {
isAvailable : false
}
const TaSupport= {
makeAssigmnet : 'JS Assighmnet',
fullTime : true,
__proto__: TeacherSupport
}
Teacher.__proto__ = user // protyple inheritance
// Modern syntax
Object.setPrototypeOf(TeacherSupport, Teacher)
// ***********************
let anotherUserName = 'chaiOrCode '
let thirdUser = ' Hello Wolrd '
String.prototype.trueLength =function(){
console.log(`${this}`);
console.log(` True Length is :${this.trim().length}`);
}
anotherUserName.trueLength();
thirdUser.trueLength();
"Shfia".trueLength()
"Coofee".trueLength()
"JavaScript".trueLength()
</script>
</body>
</html>