| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/API/Web_Workers_API/Structured_clone_algorithm | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
, HTML5 JavaScript . , JSON , . , , JSON.
, , , . , , .
JSON:
RegExp .Blob, File, FileList .ImageData . The dimensions of the clone's CanvasPixelArray will match the original and have a duplicate of the same pixel data.Error and Function objects cannot be duplicated by the structured clone algorithm; attempting to do so will throw a DATA_CLONE_ERR exception.DATA_CLONE_ERR exception.lastIndex field of RegExp objects is not preserved.| Object type | Notes |
|---|---|
| All primitive types | However not symbols |
| Boolean object | |
| String object | |
| Date | |
| RegExp | The lastIndex field is not preserved. |
Blob |
|
File |
|
FileList |
|
| ArrayBuffer | |
| ArrayBufferView | This basically means all typed arrays like Int32Array etc. |
ImageData |
|
| Array | |
| Object | This just includes plain objects (e.g. from object literals) |
| Map | |
| Set |
(. , ), . .
function clone(objectToBeCloned) {
// Basis.
if (!(objectToBeCloned instanceof Object)) {
return objectToBeCloned;
}
var objectClone;
// Filter out special objects.
var Constructor = objectToBeCloned.constructor;
switch (Constructor) {
// Implement other special objects here.
case RegExp:
objectClone = new Constructor(objectToBeCloned);
break;
case Date:
objectClone = new Constructor(objectToBeCloned.getTime());
break;
default:
objectClone = new Constructor();
}
// Clone each property.
for (var prop in objectToBeCloned) {
objectClone[prop] = clone(objectToBeCloned[prop]);
}
return objectClone;
}
window.historywindow.postMessage()This page was last modified on 24 . 2025 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |