console.log.apply not working in IE9

后端 未结 7 598
情深已故
情深已故 2020-11-29 00:32

Looks like I\'ve re-invented the wheel, but somehow this isn\'t working in Internet Explorer 9, but does in IE6.

function debug()
  if(!window.console) { 
           


        
相关标签:
7条回答
  • 2020-11-29 01:05

    The reason I came to this question was that I as trying to 'spicy' the console.log function for a specific module, so I'd have more localized and insightful debug info by playing a bit with the arguments, IE 9 broke it.

    @Andy E answer is great and helped me with lots of insight about apply. I just don't take the same approach to support IE9, so my solution is running the console only on "modern browsers" (being that modern means whatever browsers that behave the way I expect =)

    var C = function() {
      var args = Array.prototype.slice.call(arguments);
      var console = window.console;
      args[0]  = "Module X: "+args[0];
      if( typeof console == 'object' && console.log && console.log.apply ){
        console.log.apply(console, args);
      }
    };
    
    0 讨论(0)
提交回复
热议问题