@@ -32,7 +32,7 @@ prototype 的几种方法
32
32
33
33
#### 1.Object.create()方法
34
34
35
- ```
35
+ ``` javascript
36
36
let proto = {a: 1 }
37
37
let propertiesObject = {
38
38
b: {
@@ -48,7 +48,7 @@ console.log(obj.__proto__ === proto); // true
48
48
49
49
#### 2.方法继承
50
50
51
- ```
51
+ ``` javascript
52
52
// 方法继承
53
53
let proto = function () {}
54
54
proto .prototype .excute = function () {}
@@ -60,14 +60,14 @@ child.prototype = new proto()
60
60
61
61
#### 3.函数对Object的默认继承
62
62
63
- ```
63
+ ``` javascript
64
64
let Foo = function () {}
65
65
console .log (Foo .prototype .__proto__ === Object .prototype ); // true
66
66
```
67
67
68
68
#### 4.isPrototypeOf
69
69
70
- ```
70
+ ``` javascript
71
71
prototypeObj .isPrototypeOf (obj)
72
72
```
73
73
@@ -77,23 +77,23 @@ prototypeObj.isPrototypeOf(obj)
77
77
78
78
contructor.prototype是否出现在obj的原型链上
79
79
80
- ```
80
+ ``` javascript
81
81
obj instanceof contructor
82
82
```
83
83
84
84
#### 6.getPrototypeOf
85
85
86
86
Object.getPrototypeOf(obj) 方法返回指定对象obj的原型(内部[[ Prototype]] 属性的值)
87
87
88
- ```
88
+ ``` javascript
89
89
Object .getPrototypeOf (obj)
90
90
```
91
91
92
92
#### 7.setPrototypeOf
93
93
94
94
设置一个指定的对象的原型 ( 即, 内部[[ Prototype]] 属性)到另一个对象或 null
95
95
96
- ```
96
+ ``` javascript
97
97
var obj = {}
98
98
var prototypeObj = {}
99
99
Object .setPrototypeOf (obj, prototypeObj)
0 commit comments