IE 11 - console.log is displaying undefined for ob

2019-02-22 05:06发布

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>

nonsense

3条回答
Root(大扎)
2楼-- · 2019-02-22 05:09

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.

查看更多
成全新的幸福
4楼-- · 2019-02-22 05:25

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

查看更多
登录 后发表回答