Can't hide JSON value for Element.getBoundingClientRect () result

I need to convert the result of the DOMRect object returned to JSON value Element.getBoundingClientRect()

Here's an example:

http://jsfiddle.net/5vs6x6fc/2/

When used, JSON.stringify()

it returns {}

, I need a JSON value instead.

I'd like to know:

  • Why is this?
  • What could be a possible alternative solution for looping the property of the returned object r

    ex:for (var property in r){}

Notes. I am configured for Chrome.

+3


source to share


1 answer


The rect constraint contains only "virtual" properties. If you

console.log(Object.getOwnPropertyNames(r));
// or
console.log(Object.keys(r));

      



you will get an empty list. JSON.stringify()

depends on Object.keys(r)

(see comments below) and thus returns an empty object literal.

Your loop based approach seems to be an acceptable solution to this problem.

+3


source







All Articles