The result of someElement.getBoundingClientRect()
returns a special object of type ClientRect
(or DomRect
apparently)
It is structured like {top: 10, right: 20, bottom: 30, left: 10, width: 10}
Unfortunately, this object does not behave quite like other objects.
For example, using Object.keys
on it returns an empty array (I think because ClientRect
properties are not enumerable
I found something of a dirty way to convert to a plain object:
var obj = {}
for (key in rect) {
obj[key] = rect[key]
}
My question is, is there a better way?
This is something that I can live with:
You could use the extend method if you are using jQuery.
Let's not overcomplicate things!