WorkerGlobalScope:structuredClone() 方法
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.
备注: 此特性仅在 Web Worker 中可用。
WorkerGlobalScope
接口的 structuredClone()
方法使用结构化克隆算法将给定的值进行深拷贝。
该方法还支持把原值中的可转移对象转移(而不是拷贝)到新对象上。可转移对象与原始对象分离并附加到新对象;它们将无法在原始对象中被访问。
语法
js
structuredClone(value)
structuredClone(value, options)
参数
value
-
被克隆的对象。可以是任何结构化克隆支持的类型。
options
可选-
一个具有以下属性的对象:
返回值
原始值(value
)的深拷贝。
异常
DataCloneError
DOMException
-
如果输入值的任一部分不可序列化,则抛出该异常。
描述
参见 Window.structuredClone()
以获取该函数的详细信息。
示例
参见 Window.structuredClone()
以获取示例。
规范
Specification |
---|
HTML # dom-structuredclone |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
structuredClone |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- See implementation notes.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.