-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobj.html
More file actions
34 lines (26 loc) · 796 Bytes
/
obj.html
File metadata and controls
34 lines (26 loc) · 796 Bytes
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
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript 对象构造器</h1>
<p id="demo"></p>
<script>
// Person 对象的构造器函数
function Person(firstName, lastName, age, eyeColor) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.eyeColor = eyeColor;
this.changeName = function (name) {
this.lastName = name;
}
}
// 创建 Person 对象
var myFriend = new Person("Bill", "Gates", 62, "green");
// 修改姓氏
myFriend.changeName("Jobs");
// 显示姓氏
document.getElementById("demo").innerHTML =
"My friend's last name is " + myFriend.lastName;
</script>
</body>
</html>