MDN page Array#slice
状态:
For strings, numbers and booleans (not String, Number and Boolean objects), slice copies the values into the new array. Changes to the string, number or boolean in one array do not affect the other array.
作为引用类型(诚然具有值语义)的字符串文字当然不会被复制。相反,复制引用?
最佳答案
字符串文字产生不可变的原始值。这些不是引用值。
字符串可以通过 JS 引擎中的字符数组的共享引用来实现,这只是一个实现细节。正如您自己所说,字符串在 JS 中确实具有值语义,这才是最重要的。
关于javascript - Array.prototype.slice 与数组中的字符串的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44378935/