-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs对象原型.html
29 lines (24 loc) · 943 Bytes
/
js对象原型.html
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
<!DOCTYPE html>
<html>
<body>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<script>
function Person(first,last,age,eyecolor){
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
Person.prototype.fname = function(){
return this.firstName;
}
var myFriend = new Person("Gyoku","Mei",21,"black");
document.getElementById("demo1").innerHTML = "My friend is " + myFriend.fname();
document.getElementById("demo2").innerHTML = Object.getOwnPropertyNames(myFriend);
Object.defineProperty(myFriend, "fullName",{get : function(){return this.firstName+" "+this.lastName;}});
document.getElementById("demo3").innerHTML = myFriend.fullName;
</script>
</body>
</html>