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。