-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdn-oojs.html
More file actions
117 lines (112 loc) · 2.85 KB
/
Copy pathmdn-oojs.html
File metadata and controls
117 lines (112 loc) · 2.85 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
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Object-oriented JavaScript example</title>
</head>
<body>
<p>
This example requires you to enter commands in your browser's JavaScript
console (see
<a
href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools"
>What are browser developer tools</a
>
for more information).
</p>
</body>
<script>
/*
Object literal person.
Dibilang object literal kerena dipisahkan oleh koma
*/
const person = {
name: ["Bob", "Smith"],
/* calling a name : person.name= [bob, smith]
or person.name[1]= smith */
age: 32,
gender: "male",
interests: ["music", "skiing"],
bio: function() {
alert(
this.name[0] +
" " +
this.name[1] +
" is " +
this.age +
" years old. He likes " +
this.interests[0] +
" and " +
this.interests[1] +
"."
);
},
greeting: function() {
alert("Hi! I'm " + this.name[0] + ".");
}
};
const person2 = {
//- possible: object inside object
name: {
first: "Bob",
last: "Smith"
},
/*
caling a name: person2.name.first = bob
or with bracket notation instead with . dot notation
like: person2['name']['first']
*/
age: 32,
gender: "male",
interests: ["music", "skiing"],
bio: function() {
alert(
this.name[0] +
" " +
this.name[1] +
" is " +
this.age +
" years old. He likes " +
this.interests[0] +
" and " +
this.interests[1] +
"."
);
},
greeting: function() {
alert("Hi! I'm " + this.name[0] + ".");
}
/*
eyes: "hazel",
farewell: function() {
alert("Bye everybody!");
}
*/
};
person2["eyes"] = "hazel";
person2.farewell = function() {
alert("Bye everybody!");
};
const name = "anisa";
function createNewPerson(name) {
//name = "anisa";
const obj = {};
obj.name = name;
obj.greeting = function() {
alert("Hi! Im" + obj.name + ".");
};
console.log("globaler Name: " + name);
return obj;
}
const salva = createNewPerson("Salva");
function createNewPerson2(name) {
//name = "anisa";
this.name = name;
this.greeting = function() {
alert("Hi! Im" + this.name + ".");
};
console.log("globaler Name2: " + this.name);
}
const xixi = createNewPerson2("Xixi");
</script>
</html>