为什么我不能直接绑定console.log在IE9与开发工具打开? [英] Why can't I bind directly console.log on IE9 with developer tools open?

查看:414
本文介绍了为什么我不能直接绑定console.log在IE9与开发工具打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE9中打开开发工具时,此代码的工作原理:

With developer tools open in IE9, this code works :

var log = Function.prototype.bind(console.log, console);

但如果我输入

console.log(console, console.log);
var log = console.log.bind(console);

那么我得到:

img src =https://i.stack.imgur.com/3sIEj.pngalt =SCRIPT438:对象不支持属性或方法bind>

为什么?

这是已知的IE错误还是正常的行为?

Is that a known IE bug or a normal behavior ?

函数(我没有问题, window.alert 这也是本机的)?

Does it affect other functions (I had no problem with window.alert which is also native) ?

推荐答案

正如相关答案所说,只是因为 log 函数从IE中的控制台 '继承 Function 。它是一个宿主对象,它使用任何规则IE认为合适。

As the related answer says, it is simply because the log function from the console object in IE doesn't inherit from Function. It's a host object, and it uses whatever rules IE sees fit.

但它是一个函数式。这就是为什么使用 Function.prototype.bind 工作,就像使用 Array.prototype.forEach 在数组类对象。 (提示:NodeLists和HTMLCollections。)

But it's a function-like. That's why using Function.prototype.bind works, just like using Array.prototype.forEach works on array-like objects. (Hint: NodeLists and HTMLCollections.)

这不是一个bug本身,因为没有规范谈论控制台 object。 DOM生活标准甚至没有提及。所以每个浏览器按照它想要的方式实现这个对象。

It's not a bug per se, because there is no specification talking about the console object. The DOM living standard doesn't even mention it. So each browser implements this object the way it wants to.

这意味着 window.alert 也是同样的问题。我们很幸运,它在各种浏览器中运行良好。

And it does mean that the window.alert function is subject to the same problems. We're lucky that it works so well across browsers.

这是IE。处理它。虽然IE9远远优于IE8,但它仍然比其他现代浏览器更糟糕。

That's IE. Deal with it. Although IE9 is far better than IE8, it's still way worse than the other modern browsers.

这篇关于为什么我不能直接绑定console.log在IE9与开发工具打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆