1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-25 03:02:21 +00:00

Fix coding style in docs/class.md

This commit is contained in:
Xcat Liu 2016-05-18 16:19:26 +08:00
parent 307932e155
commit 96b4a4a33d

View File

@ -14,7 +14,7 @@ function Point(x,y){
Point.prototype.toString = function () {
return '(' + this.x + ', ' + this.y + ')';
}
};
```
上面这种写法跟传统的面向对象语言比如C++和Java差异很大很容易让新学习这门语言的程序员感到困惑。
@ -74,7 +74,7 @@ class Point {
Point.prototype = {
toString(){},
toValue(){}
}
};
```
在类的实例上面调用方法,其实就是调用原型上的方法。
@ -100,7 +100,7 @@ class Point {
Object.assign(Point.prototype, {
toString(){},
toValue(){}
})
});
```
`prototype`对象的`constructor`属性直接指向“类”的本身这与ES5的行为是一致的。
@ -133,11 +133,11 @@ Object.getOwnPropertyNames(Point.prototype)
```javascript
var Point = function (x, y){
// ...
}
};
Point.prototype.toString = function() {
// ...
}
};
Object.keys(Point.prototype)
// ["toString"]
@ -585,7 +585,7 @@ var obj = {
toString() {
return "MyObject: " + super.toString();
}
}
};
obj.toString(); // MyObject: [object Object]
```