add: 函数的定义
This commit is contained in:
@@ -79,10 +79,32 @@ window.open('你所要跳转的新页面');
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### 2019-12-10-JavaScript 新特性:Optional Chaining(可选链式调用)语法
|
||||
|
||||
以往写代码,我们一般都这么写:
|
||||
|
||||
```javascript
|
||||
if (result && result.user && result.user.name && result.user.name.length) {
|
||||
console.log('qianguyihao');
|
||||
}
|
||||
```
|
||||
|
||||
有了 Optinal Chain 语法之后,就简洁很多了,可以这么写:
|
||||
|
||||
|
||||
```javascript
|
||||
if (result?.user?.name?.length) {
|
||||
console.log('qianguyihao');
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
参考链接:
|
||||
|
||||
- 了解 JavaScript 新特性:Optional Chaining:<https://www.infoq.cn/article/2JDORgXrU6VmZ7jlyuFD>
|
||||
|
||||
- 原文链接: https://v8.dev/features/optional-chaining
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user