Does IE9 support console.log, and is it a real function?

后端 未结 7 634
醉话见心
醉话见心 2020-11-22 06:16

In which circumstances is window.console.log defined in Internet Explorer 9?

Even when window.console.log is defined, window.console.

相关标签:
7条回答
  • 2020-11-22 06:50

    In Internet Explorer 9 (and 8), the console object is only exposed when the developer tools are opened for a particular tab. If you hide the developer tools window for that tab, the console object remains exposed for each page you navigate to. If you open a new tab, you must also open the developer tools for that tab in order for the console object to be exposed.

    The console object is not part of any standard and is an extension to the Document Object Model. Like other DOM objects, it is considered a host object and is not required to inherit from Object, nor its methods from Function, like native ECMAScript functions and objects do. This is the reason apply and call are undefined on those methods. In IE 9, most DOM objects were improved to inherit from native ECMAScript types. As the developer tools are considered an extension to IE (albeit, a built-in extension), they clearly didn't receive the same improvements as the rest of the DOM.

    For what it's worth, you can still use some Function.prototype methods on console methods with a little bind() magic:

    var log = Function.prototype.bind.call(console.log, console);
    log.apply(console, ["this", "is", "a", "test"]);
    //-> "thisisatest"
    
    0 讨论(0)
提交回复
热议问题