gpt4 book ai didi

javascript - getBoundingClientRect() 对象属性不可复制

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:59:52 25 4
gpt4 key购买 nike

<分区>

function test(o) {
console.log("Object:", o);
console.log("Assign test:", Object.assign({}, o));
console.log("Keys test:", Object.keys(o));
console.log("JSON test:", JSON.stringify(o));
}

var el = document.getElementById("question"); /* or document.body */

test(el.style); /* works as expected */
test(el.getBoundingClientRect()); /* behaves like {} */
test(Object.assign(el.getBoundingClientRect(),{aaaa: 1111})); /* works... only for aaaa */

为什么?

输出(测试结果)

参见 PasteBin .

MDN 文档

  1. Element.getBoundingClientRect()
  2. DOMRect

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com