;(function (global) {
global.console = global.console || {};
var timers = {}
, property
, properties = 'memory'.split(',')
, method
, methods = ('assert,clear,count,debug,dir,dirxml,error,exception,'
+ 'group,groupCollapsed,groupEnd,info,log,markTimeline,'
+ 'profile,profiles,profileEnd,show,table,time,timeEnd,'
+ 'timeline,timelineEnd,timeStamp,trace,warn').split(',');
while (properties.length > 0) {
property = properties.pop();
if (!global.console.hasOwnProperty(property)) {
global.console[property] = {};
}
}
while (methods.length > 0) {
method = methods.pop();
if (
!global.console.hasOwnProperty(method)
|| Object.prototype.toString.call(global.console[method]) !== '[object Function]'
) {
if (
method === 'log'
|| method === 'debug'
|| method === 'info'
|| method === 'warn'
|| method === 'error'
|| method === 'exception'
|| method === 'dir'
|| method === 'dirxml'
) {
global.console[method] = function (message) {alert(message);};
} else if (
method === 'assert'
) {
global.console[method] = function() {
var args = Array.prototype.slice.call(arguments, 0)
, expression = args.shift();
if (!expression) {
args[0] = 'Assertion failed: ' + args[0];
console.error.apply(console, args);
}
};
} else if (
method === 'time'
) {
global.console[method] = function (id) {
timers[id] = new Date().getTime();
};
} else if (
method === 'timeEnd'
) {
global.console[method] = function (id) {
var start = timers[id];
if (start) {
global.console.log(id + ': ' + (new Date().getTime() - start) + 'ms');
delete timers[id];
}
};
} else {
global.console[method] = function () {};
}
}
}
})(this);
console.log(111);
console.assert(1 > 2, 'b');
console.time('one');
console.timeEnd('one');
console.dir([1,2]);
Комментариев нет:
Отправить комментарий