console.log.apply not working in IE9

后端 未结 7 619
情深已故
情深已故 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 00:47

    There is also Paul Irish's way of doing it. It is simpler than some of the answers above, but makes log always output an array (even if only one argument was passed in):

    // usage: log('inside coolFunc',this,arguments);
    // http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
    window.log = function(){
      log.history = log.history || [];   // store logs to an array for reference
      log.history.push(arguments);
      if(this.console){
        console.log( Array.prototype.slice.call(arguments) );
      }
    };
    

提交回复
热议问题