So I (minorly) kvetched about how when exploring $ in devtools, jQuery is represented as a fabulous string:
I use the console a lot to explore libraries, discover functionality, etc. Coupled with that, I’ve also started using both Chrome and Firefox devtools to try and become a master of both (and also get used to regular cross browser testing/debugging).
So why DO names in Chrome look all cray? In Firefox, when I put a function into the REPL, something different happens.
Neither of these are telling me the name. Or directly accessible information about the library. Awesome. Do you know how to get the version/library information in jQuery? Here’s how.
Because that’s not obfuscated. What I’d love to see is things more like this (note, getVersion would make sense as a function name, I was just trying things out):
Ember does this, and it’s awesome:
So when I started looking into this, I ended up in an interesting place — I wanted to argue that instead of that first picture of jQuery, when I type jQuery into the console, I’d like to see some useful information instead. However, it turns out that what Chrome is doing is calling the toString() method on a function when it represents in the REPL.
You know what you can do with arbitrary methods? Redefine them!
Let’s maybe put some useful version numbers into our libraries in a standard way. Quite a few of them do, like Backbone! Angular (although theirs is lowercase and an object … I like the caps string version), Knockout (also lowercase, but a string). With jQuery, I’m sure part of it is related to jQuery() being an init function and not an object like the major frameworks (and as such, it’s burdened with that toString functionality in Chrome console rather than showing an object that might expose the version key).
And maybe it’s not a good idea that Chrome’s calling toString? I discussed this with Michael Ficarra and Brian McKenna at NationJS yesterday (who are both super awesome and nice and I totally did not understand their talks since they went over my head), and Michael suggested it was bug-report type stuffs. What do you think? Searching the bugs, it looks like toString is also used for Date objects, and you can crash it using debugger;. Cool! (?) Kinda looks like Firefox is doing the smart thing here.