Skip to content

Instantly share code, notes, and snippets.

@flowerains
Created March 7, 2015 19:24
Show Gist options
  • Save flowerains/0c935a5829557a0b1de5 to your computer and use it in GitHub Desktop.
Save flowerains/0c935a5829557a0b1de5 to your computer and use it in GitHub Desktop.
console.js,看见的一个非常好的小插件,感谢作者"颜海镜"
;(function(g) {
'use strict';
var _console = g.console || {};
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'exception', 'error', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
var console = {version: '0.1.0'};
var key;
for(var i = 0, len = methods.length; i < len; i++) {
key = methods[i];
console[key] = function (key) {
return function () {
if (typeof _console[key] === 'undefined') {
return 0;
}
Function.prototype.apply.call(_console[key], _console, arguments);
};
}(key);
}
g.console = console;
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment