IE 11 - console.log is displaying undefined for object properties

别说谁变了你拦得住时间么 提交于 2019-12-01 16:27:03

问题


This is a pretty short example. I copy and paste the code below into a file, save it, and open it. Works fine in Chrome, fails in ie 11.

The output on the console is nonsense! What's going on? Have a stumbled upon some strange bug?

test.b is clearly not undefined, as it is accessible by the JSON parser and by direct object evaluation.

Also, switching around the order of the variables in the log function does nothing to change test.b being undefined.

<!DOCTYPE html>
<html>
<head>
   <title>wtf</title>
   <script>
      var test = {a:1,b:{c:1}}
      console.log(test,JSON.stringify(test),test.b);
    </script>
</head>
<body>
    WTF IE
</body>
</html>


回答1:


A bug report has been accepted by microsoft.

http://connect.microsoft.com/IE/feedbackdetail/view/958116/console-log-bug-on-11-0-9600-17239-displays-undefined-undefined-for-objects-and-arrays-which-are-properties-of-objects

So the answer appears to be, at this time, that it's a bug.




回答2:


You have to write your own recursive log function, because the browser only logs on the first level. To log all by default would cost too much performance and memory for the browser. See: recursive log function




回答3:


I recently ran into this issue as well.

The issue was that the page i was working on had compatibility mode set to IE8.

<meta http-equiv="X-UA-Compatible" content="IE=8" >

I believe IE8 did not have console, so console.log would be undefined.



来源:https://stackoverflow.com/questions/25542661/ie-11-console-log-is-displaying-undefined-for-object-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!