In the interests of this experiment I've created a log() function, which uses either console.log() or console.dir(), depending on whether the input is a string or an object. This is kind of dumb, but, hey, why not. Thanks to type coercion my “labelled variable” output magically turns into a string. That’s probably not bullet-proof, but for now it’s fun and fine.
I don’t regularly use console.group() and console.groupEnd() though they’re nice when you have more complex or lengthy outputs, or just want to clearly label, like I was doing in those previous samples, having different sets of clearly labelled outputs. Looking at that functionality now, I wondered if I could turn the group method into a friendlier function, one that would automate calling groupEnd and which would help enforce clear indentation in the code editor to show where the console logging starts and stops.
I wound up with a basic group() function, which takes a label for the group, the code (which needs to be wrapped in an anonymous function, so that the group function can execute it), and a ‘collapsed’ flag, which will call either group or groupCollapsed depending on whether that flag is set or not.
On the one hand, hey, that’s fun! What a fun thing I just did! On the other hand, I'm sure there's problems with it. Variable scoping problems, probably? Something here will come back to bite me later. It also just feels like a weird little way to save a modicum of effort. So I don't know if this will stick, but exploring possibilities is fun.