DOMPointReadOnly.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.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

メソッド toJSON() は、この点オブジェクトの JSON 形式を表すオブジェクトを返します。

構文

js
toJSON();

引数

なし。

返値

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

この例では、現在のウィンドウの左上隅をスクリーン座標で表す DOMPoint オブジェクトを作成し、それを JSON に変換しています。

js
var topLeft = new DOMPoint(window.screenX, window.screenY);

var pointJSON = topLeft.toJSON();

仕様書

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

ブラウザーの互換性