Symbol.isConcatSpreadable 设置成false或者undefined意义不一样吗?

image.png

上方截图取自红宝书《JavaScript高级程序设计》,我的理解是在concat在连接数组的时候需要查看属性Symbol.isConcatSpreadable的值是真值还是假值。

如果为假值就不打平数组,把整个数组连接到数组的最后,但是事实上并不是这样的?

这是我自己测试的截图

image.png

大佬们知道这是为什么吗?

对于真·数组来说,没有 @@isConcatSpreadable 这个 symbol 也是没有关系的,数组默认支持 concat spreabable,除非你手动设置一个非 undefined 的值。

参见 ES6 的 Spec:

Runtime Semantics: IsConcatSpreadable ( O )

The abstract operation IsConcatSpreadable with argument O performs the following steps:

If Type(_O_) is not Object, return false. Let spreadable be Get(_O_, @@isConcatSpreadable). ReturnIfAbrupt(_spreadable_). If spreadable is not undefined, return ToBoolean(_spreadable_). Return IsArray(_O_).

参考:
ES6 spec sec-isconcatspreadable: https://262.ecma-internationa...