Home > Article > Web Front-end > Why is console.log in Internet Explorer 9 Only Available When Developer Tools are Open?
Console.log in Internet Explorer 9: Accessibility and Implementation
Internet Explorer 9 introduces support for the console.log function, but its availability is contingent upon certain conditions.
Availability of window.console.log
The window.console.log function is defined in Internet Explorer 9 only when the developer tools window is active for the current tab. This means that:
Absence of console.log.apply and console.log.call
While window.console.log is defined in Internet Explorer 9, its apply and call methods are not. This is because the console object in IE9 is not fully standardized and is considered an extension to the Document Object Model (DOM). As a host object, the console object is not required to inherit methods from either Object or Function, unlike native ECMAScript objects.
Method Invocation using bind()
Despite the absence of apply and call, it is still possible to use Function.prototype methods on console methods. This can be achieved using the bind() method:
var log = Function.prototype.bind.call(console.log, console); log.apply(console, ["this", "is", "a", "test"]); // outputs "thisisatest"
The above is the detailed content of Why is console.log in Internet Explorer 9 Only Available When Developer Tools are Open?. For more information, please follow other related articles on the PHP Chinese website!