forked from liamnewmarch/console-shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console-shim.js
32 lines (32 loc) · 1.15 KB
/
console-shim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* https://github.com/liamnewmarch/console-shim 2014 CC-BY @liamnewmarch */
if (!('console' in window)) {
(function() {
var Console, __console;
Console = function() {
var check, key, log, methods, _i, _len, _ref;
this.__buffer = [];
log = function() {
return this.__buffer.push(arguments);
};
methods = 'assert count debug dir dirxml error exception info log trace warn';
_ref = methods.split();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i];
this[key] = log;
}
check = setInterval(function() {
var data, func, _j, _len1, _ref1, _ref2;
if ((((_ref1 = window.console) != null ? _ref1.log : void 0) != null) && !console.__buffer) {
clearInterval(check);
func = Function.prototype.bind ? Function.prototype.bind.call(console.log, console) : console.log;
_ref2 = __console.__buffer;
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
data = _ref2[_j];
func.apply(console, data);
}
}
}, 1000);
};
return __console = window.console = new Console();
})();
}