mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-25 03:02:21 +00:00
docs: edit reflect & destructuring
This commit is contained in:
parent
90df0a9236
commit
0af61084ee
@ -352,6 +352,7 @@ let x;
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// 正确的写法
|
// 正确的写法
|
||||||
|
let x;
|
||||||
({x} = {x: 1});
|
({x} = {x: 1});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -415,19 +415,19 @@ Reflect.isExtensible(1) // 报错
|
|||||||
var myObject = {};
|
var myObject = {};
|
||||||
|
|
||||||
// 旧写法
|
// 旧写法
|
||||||
Object.isExtensible(myObject) // true
|
Object.preventExtensions(myObject) // Object {}
|
||||||
|
|
||||||
// 新写法
|
// 新写法
|
||||||
Reflect.preventExtensions(myObject) // true
|
Reflect.preventExtensions(myObject) // true
|
||||||
```
|
```
|
||||||
|
|
||||||
如果参数不是对象,`Object.isExtensible`在 ES5 环境报错,在 ES6 环境返回这个参数,而`Reflect.preventExtensions`会报错。
|
如果参数不是对象,`Object.preventExtensions`在 ES5 环境报错,在 ES6 环境返回传入的参数,而`Reflect.preventExtensions`会报错。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// ES5
|
// ES5 环境
|
||||||
Object.preventExtensions(1) // 报错
|
Object.preventExtensions(1) // 报错
|
||||||
|
|
||||||
// ES6
|
// ES6 环境
|
||||||
Object.preventExtensions(1) // 1
|
Object.preventExtensions(1) // 1
|
||||||
|
|
||||||
// 新写法
|
// 新写法
|
||||||
|
Loading…
x
Reference in New Issue
Block a user