Skip to content

Instantly share code, notes, and snippets.

@FGRibreau
Created June 15, 2010 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FGRibreau/439739 to your computer and use it in GitHub Desktop.
Save FGRibreau/439739 to your computer and use it in GitHub Desktop.
//Do this only one time !
makeChainable(console, 'assert clear count debug dir dirxml error exception group groupCollapsed groupEnd info log profile profileEnd time timeEnd warn'.split(' '));
//Usage:
console
.profile()
.time('testTime')
.group('GroupTest')
.debug('test', 1, 2, 3)
.warn('warniiing!')
.log('loo', true)
.dir([1, 2, 3, 4])
.info('plop')
.groupEnd('GroupTest')
.timeEnd('testTime')
.profileEnd();
var makeChainable = function(obj, method) {
var m = Object.prototype.toString.call(method) === "[object Array]" ? method: [method],
i = m.length;
while (i--) {
obj[m[i]] = function(o) {
return function() {
o.apply(this, arguments);
return this;
}
} (obj[m[i]]);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment