JSON stringify为非空对象输出空对象

时间:2016-07-21 13:25:07

标签: javascript

Fiddle

为什么JSON.stringify会产生一个空对象?

window.addEventListener("resize", updateDimensions);
function updateDimensions(){
    var node = document.getElementById('sample');
    var windowDimensions = {width: window.innerWidth, height: window.innerHeight};
    var dimensions = node.getBoundingClientRect();

  console.log('dimensions', dimensions);//dimensions is ClientRect {top: X, right: ...} 

var result = ' dimensions: ' + JSON.stringify(dimensions)
             + ' windowDimensions: ' + JSON.stringify(windowDimensions); 

  console.log(result);//now dimensions is {}
}

<div id="output"></div>

<div id="sample">
  Hello World
</div>

#sample {
 padding: 20px;
 max-height: 380px;
 overflow-y: auto;
 max-width: 150px;
 border: solid blue;
 margin-left: 250px;
 margin-top: 100px;
}

0 个答案:

没有答案