根据结构化克隆算法,`Math` 是可克隆的吗?
`Math` is cloneable per Structured Cloning Algorithm?
以下不会在 Chrome 中抛出 DataCloneError
DOMException
:
self.postMessage(Math, '*');
这是structured cloning algorithm的预期行为吗?
它在 IndexedDB test 中使用(当前没有失败导致测试将 Math
视为可克隆(尽管无效)的键路径键)所以我很好奇...
Math
的函数属性不可枚举(参见 here and here), so they would be skipped by StructuredClone.
Object.getOwnPropertyDescriptor(Math, 'abs').enumerable
在上面评论的 Beth
示例中,func
最终出现在原型上,因此它不是 "own property",因此也被忽略了。
似乎是 FF 中的一个错误。
以下不会在 Chrome 中抛出 DataCloneError
DOMException
:
self.postMessage(Math, '*');
这是structured cloning algorithm的预期行为吗?
它在 IndexedDB test 中使用(当前没有失败导致测试将 Math
视为可克隆(尽管无效)的键路径键)所以我很好奇...
Math
的函数属性不可枚举(参见 here and here), so they would be skipped by StructuredClone.
Object.getOwnPropertyDescriptor(Math, 'abs').enumerable
在上面评论的 Beth
示例中,func
最终出现在原型上,因此它不是 "own property",因此也被忽略了。
似乎是 FF 中的一个错误。