Home >Web Front-end >JS Tutorial >Is window.console.log.apply and window.console.log.call Defined in IE9?
IE9's Console.log: Availability and Functionality
Internet Explorer 9's support for window.console.log is a topic that often raises questions. This article delves into the circumstances under which window.console.log is accessible and explores specific inconsistencies with window.console.log.apply and window.console.log.call.
When Is window.console.log Defined in IE9?
In Internet Explorer 9 (and 8), the console object appears only when the Developer Tools are activated for a particular tab. Closing the Developer Tools window within that tab retains access to the console object for subsequent pages. However, opening a new tab requires manually activating the Developer Tools to expose the console object.
Undefined window.console.log.apply and window.console.log.call
The console object in IE9 is not part of any established standard and is considered an extension to the DOM. Unlike native ECMAScript functions and objects, the console object is not inherently connected to the Object prototype or its methods, such as Function.apply and Function.call. This distinction explains why these methods are undefined for console object functions in IE9.
Other Browser Implementations
In later versions of Internet Explorer, most DOM objects inherit from native ECMAScript types, enhancing their functionality. However, as the Developer Tools are an extension to IE, they did not benefit from these improvements, resulting in the continued absence of apply and call methods for console object functions.
Using Function Methods with console Object Functions
While window.console.log.apply and window.console.log.call are not directly accessible in IE9, it is still possible to employ Function.prototype methods through the bind() function:
var log = Function.prototype.bind.call(console.log, console); log.apply(console, ["this", "is", "a", "test"]); //-> "thisisatest"
The above is the detailed content of Is window.console.log.apply and window.console.log.call Defined in IE9?. For more information, please follow other related articles on the PHP Chinese website!