let {toString: s} = 123; console.log(s) // ƒ toString() { [native code] }
- 如果等号右边是数值和布尔值,则会先转为对象。
let {toString: s} = false; console.log(s) // ƒ toString() { [native code] }
-
undefined
和null
无法转为对象
let { prop: x } = undefined; let { prop: y } = null; console.log(x) // TypeError console.log(y) // TypeError