-
Notifications
You must be signed in to change notification settings - Fork 1
/
原型链继承.html
55 lines (44 loc) · 943 Bytes
/
原型链继承.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
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
<!DOCTYPE html>
<html>
<head>
<title>原型链继承</title>
</head>
<body>
</body>
<script type="text/javascript">
var huazhen = function(){
this.coding = function(){
console.log("coding.....")
}
}
var baby = function(){
this.eat = function(){
console.log("eat nai...")
}
}
baby.prototype = new huazhen();
var smallBaby = new baby();
smallBaby.coding();
console.log(smallBaby);
/*--------------------------------------------*/
//所以的原型链顶层都是object
var Weiqiyan = function(){
}
Weiqiyan.prototype.detail = "漂亮";
Weiqiyan.prototype.sex = "女";
Weiqiyan.prototype.shopping = function(){
console.log("shopping.....");
}
var secendBaby = function(){
}
secendBaby.prototype = new Weiqiyan();
var baby2 = new secendBaby();
console.log(baby2.sex)
baby2.sex = "男";
//修改原型链属性
baby2.__proto__.sex = "不清楚"
console.log(baby2);
var xifu = new Weiqiyan();
console.log(xifu)
</script>
</html>