问题描述:

Try this in dev tools console:

JSON.stringify(document.body.getBoundingClientRect())

the output is {}, instead of something sensible.

Any ideas?

网友答案:

JSON.stringify internally uses a method called toJSON.

You can specify it for your object or in your case, override it:

ClientRect.prototype.toJSON = function(){ return { top: this.top } }

JSON.stringify(document.body.getBoundingClientRect())

"{"top":-583}"
相关阅读:
Top