DOMRectReadOnly: toJSON() メソッド

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.

メモ: この機能はウェブワーカー内で利用可能です。

DOMRectReadOnlytoJSON() メソッドは、この DOMRectReadOnly オブジェクトの JSON 表現を返します。

構文

js
toJSON()

引数

なし。

返値

新しいオブジェクト。そのプロパティは、メソッドが呼び出された DOMRectReadOnly の値に設定されます。

この例では、位置 (10, 20)、幅 100、高さ 50 の矩形を表す DOMRectReadOnly を作成します。次に、toJSON() を呼び出して、矩形の JSON 表現を取得します。

js
const rect = new DOMRectReadOnly(10, 20, 100, 50);

const rectJSON = rect.toJSON();
console.log(rectJSON);
// 出力: { x: 10, y: 20, width: 100, height: 50, top: 20, right: 110, bottom: 70, left: 10 }

仕様書

Specification
Geometry Interfaces Module Level 1
# dom-domrectreadonly-tojson

ブラウザーの互換性