[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/API/Web_Workers_API/Structured_clone_algorithm [Back]  [Original]

The structured clone algorithm - Web API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

The structured clone algorithm

The structured clone JavaScript HTML5 specification . JSON . . structured clone JSON .

. .

In this article

JSON

JSON structured clone .

structured clones

  • Error Function structured clone ; DATA_CLONE_ERR exception .
  • DOM node DATA_CLONE_ERR exception .
  • :
    • RegExp lastIndex .
    • Property descriptors, setters, getters ( ) . - . .
    • .

Supported types

Object type Notes
All primitive types .
Boolean object
String object
Date
RegExp lastIndex .
Blob
File
FileList
ArrayBuffer
ArrayBufferView int32Array typed arrays .
ImageData
Array
Object plain .(e.g. )
Map
Set

: (deep copy)

(deep copy) ( ), . .

js
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;
}

: RegExp, Array, Date . .

See also


Web Proxy Viewer  |  New URL  |  Original Page