forked from mdn/content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
72 lines (54 loc) · 2.31 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: structuredClone()
slug: Web/API/structuredClone
tags:
- API
- DOM
- Method
- NeedsCompatTable
- Reference
- structuredClone
browser-compat: api.structuredClone
---
<div>{{APIRef("HTML DOM")}}</div>
<p>The global <strong><code>structuredClone()</code></strong> method deep clones a given value using the <a href="/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm">structured clone algorithm</a>.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="brush: js">const <var>clonedValue</var> = structuredClone(<var>value</var>[, { <var>transfer</var> }]);
</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
<dt><code><var>value</var></code></dt>
<dd>The value to be cloned. This can be any <a
href="/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm">structured-clonable
type</a>.</dd>
<dt><code><var>transfer</var></code> {{optional_inline}}</dt>
<dd>A sequence of objects that are <a
href="/en-US/docs/Web/API/Transferable">transferred</a> with value. The
ownership of these objects is transfered from the input value to the cloned value
that is returned.</dd>
</dl>
<h3 id="Return_value">Return value</h3>
<p>The returned <code><var>clonedValue</var></code> is a clone of the original passed
<code><var>value</var></code>, with transfered values for items passed in the
<code><var>transfer</var></code> array.</p>
<h2>Description</h2>
<p>This function can be used to deep copy JavaScript values. The structured clone algorithm
also supports circular references. The below example demonstrates this:</p>
<pre class="brush: js">// Create an object with a value and a circular reference to itself.
const original = { name: "MDN" };
original.itself = original;
// Clone it
const clone = self.structuredClone(original);
console.assert(clone !== original); // object are not the same (not same identity)
console.assert(clone.name === "MDN"); // they do have the same values
console.assert(clone.itself === clone); // and the circular reference is preserved
</pre>
<h2 id="Specifications">Specifications</h2>
<p>{{Specifications}}</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li><a
href="/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm">Structured clone algorithm</a></li>
</ul>