4 ms·
function myLog() { if(window.console && window.console.log) { window.console.log(arguments) } }
by psadauskas 15y ago
function myLog() {
if(window.console && window.console.log) {
window.console.log(arguments)
}
}
- Inviz 15y agoWhat do you think happens when you pass arguments to functions like that?
- jdunck 15y agowindow.console.log.apply(window.console, arguments)
- Inviz 15y agoSee? There's the problem. Since there's no conclusion between vendors on console object API, console.log function may not have .apply method. It's not only the console object functions actually, most of the browsers choke on a [1,2,3].forEach(alert) and other [Native Code] functions.
- gonchuki 15y agoFunction.prototype.apply.apply(console.log, [console, arguments]); Works both on IE9 broken console.log, and regular console.log from other vendors. Same hack as using Array.prototype.slice to convert arguments into a real array.
- deleted 15y ago[deleted]