DOMRectReadOnly: toJSON() 方法
注意:此功能在 Web Workers 中可用。
DOMRectReadOnly
接口的 toJSON()
方法返回 DOMRectReadOnly
对象的 JSON 表示。
语法
js
toJSON()
参数
无。
返回值
一个新对象,其属性值设置为调用该方法的 DOMRectReadOnly
对象中的值。
示例
此示例创建一个 DOMRectReadOnly
对象,表示一个位于 (10, 20)
位置,宽度为 100
,高度为 50
的矩形。然后调用 toJSON()
方法来获取该矩形的 JSON 表示。
js
const rect = new DOMRectReadOnly(10, 20, 100, 50);
const rectJSON = rect.toJSON();
console.log(rectJSON);
// Output: { x: 10, y: 20, width: 100, height: 50, top: 20, right: 110, bottom: 70, left: 10 }
规范
规范 |
---|
Geometry Interfaces Module Level 1 # dom-domrectreadonly-tojson |
浏览器兼容性
加载中…