javascript console对象的兼容性解决方案

/**
 * 
 * @authors Benjamin(http://blog.csdn.net/cuew1987)
 */
(function (win){  
	//重置为空函数,避免JS报错  
	var 
	console = win.console || {},
	fns = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml',  
	             'error', 'exception', 'group', 'groupCollapsed', 'groupEnd',  
	             'info', 'log', 'markTimeline', 'profile', 'profileEnd',  
	             'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
	i = 0,
	fn = "",
	ilen = fns.length; 
	for(; i < ilen; i++) {  
	    func = fns[i];  
	    console[fn] = console[fn] || function(){};  
	}  
})(window);


 

你可能感兴趣的:(javascript console对象的兼容性解决方案)