以下内容不会在 Chrome 中引发 DataCloneError
DOMException
:
self.postMessage(Math, '*');
这是 structured cloning algorithm 的预期行为吗? ?
它正在 IndexedDB test 中使用(当前缺乏失败导致测试将数学视为可克隆(尽管无效)的键路径 key )所以我很好奇......
最佳答案
Math
的函数属性不可枚举(请参阅 here 和 here ),因此它们将被 StructuredClone 跳过。 .
Object.getOwnPropertyDescriptor(Math, 'abs').enumerable
在上面注释中的 Beth
示例中,func
最终出现在原型(prototype)上,因此它不是“自己的属性”,因此也被忽略。
看起来像是 FF 中的一个错误。
关于javascript - `Math` 可以按照结构化克隆算法克隆吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41758510/