DOMQuad: toJSON() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Note: This feature is available in Web Workers.

Phương thức toJSON() của DOMQuad trả về biểu diễn JSON của đối tượng DOMQuad.

Cú pháp

js
toJSON()

Tham số

Không có.

Giá trị trả về

Một đối tượng mới có các thuộc tính được đặt theo các giá trị trong DOMQuad mà phương thức được gọi trên đó.

Ví dụ

Ví dụ này tạo một DOMQuad với bốn đối tượng DOMPoint đại diện cho các góc của cửa sổ hiện tại, theo tọa độ màn hình, rồi chuyển đổi sang JSON.

js
const topLeft = new DOMPoint(window.screenX, window.screenY);
const topRight = new DOMPoint(
  window.screenX + window.innerWidth,
  window.screenY,
);
const bottomLeft = new DOMPoint(
  window.screenX,
  window.screenY + window.innerHeight,
);
const bottomRight = new DOMPoint(
  window.screenX + window.innerWidth,
  window.screenY + window.innerHeight,
);

const quad = new DOMQuad(topLeft, topRight, bottomRight, bottomLeft);

const quadJSON = quad.toJSON();

Thông số kỹ thuật

Thông số kỹ thuật
Geometry Interfaces Module Level 1
# dom-domquad-tojson

Tương thích trình duyệt