I've seen the code for this function in John Resig's book 'Secrets of JavaScript Ninja' yesterday.
I considered it useful at once because I've disliked repeatedly typing console.log
for some time.
Here's my implementation of a helper function to reduce typing:
// -- Function definition -------------
// Helper function for to simplify the
// usage of console.log().
// -- Parameter -----------------------
// Pass as many parameter as you like.
// Separate them with commas.
function l() {
console.log.apply(console, arguments);
}
Usage examples:
var car = new Car(180, 'Fiat');
var someArbitraryNumber = 248;
l('My car', car, ' - ', someArbitraryNumber);
l(123, 'abc', false, 248, 'A', ' > --- < ')
Output:
My car Car { color="red", maxFuel=40, speed="180 km"} - 248 123 abc false 248 A > --- <
What's great about it: instead of typing console.log(...)
, you can type l(...);
much quicker! This simple helper behaves exactly like console.log
. For example, the parameters can be any mixture of types, and objects printed on your browser console can be expanded to see their content, they aren't converted to string representations.
If there are any ideas to improve / enhance the function I would be pleased to get that feedback.
console.log
. It isn't a real helper since it isn't helping on anything. I see no difference between your code andconsole.log(...)
. \$\endgroup\$