mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2024-04-21 12:32:22 +00:00
新建style.md
This commit is contained in:
+4
-2
@@ -54,8 +54,8 @@ log('Hello', '') // Hello
|
||||
```javascript
|
||||
|
||||
function Point(x = 0, y = 0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
var p = new Point();
|
||||
@@ -63,6 +63,8 @@ var p = new Point();
|
||||
|
||||
```
|
||||
|
||||
除了简洁,ES6的写法还有两个好处:首先,阅读代码的人,可以立刻意识到哪些参数是可以省略的,不用查看函数体或文档;其次,有利于将来的代码优化,即使未来的版本彻底拿到这个参数,也不会导致以前的代码无法运行。
|
||||
|
||||
默认值的写法非常灵活,下面是一个为对象属性设置默认值的例子。
|
||||
|
||||
```javascript
|
||||
|
||||
Reference in New Issue
Block a user