4 ms·
$.answer=42
- Tarang 13y agoA bit of context: http://en.wikipedia.org/wiki/Phrases_from_The_Hitchhiker's_Guide_to_the_Galaxy#The_number_42 http://en.wikipedia.org/wiki/Phrases_from_The_Hitchhiker's_G...
- jt2190 13y ago$ is what? [1] [1] For those not in on the joke: http://en.wikipedia.org/wiki/42_(number)#The_Hitchhiker.27s_Guide_to_the_Galaxy http://en.wikipedia.org/wiki/42_(number)#The_Hitchhiker.27s_...
- Aurel1us 13y agoAn identifier must start with $, _, or any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”. From: http://stackoverflow.com/questions/1661197/valid-characters-for-javascript-variable-names http://stackoverflow.com/questions/1661197/valid-characters-...
- gprasanth 13y ago6*9
- dm2 13y agovar $=function(a){J(1);Z.D[G](Z,[arguments])}; $ is a function object. $.answer is a property of that object. $ itself doesn't really mean anything special in javascript. jQuery and other libraries often use $ as their main object, so it's probably best to avoid using it unless you need to or it's wrapped in another function.
- uxp 13y agoThe only thing I've learned in the years that I've been writing Javascript is that the dollar symbol variable is as contentious as the West Bank. Obviously there has to be globals somewhere or else a library ceases to be a library in JS, but I see no problem is using the word jQuery explicitly, or simply passing it into a SEAN/IIFE: (function($) { $('#thing').hide(); })(jQuery);
- panzi 13y agoYes, that's how you write a jQuery module. That's how I do it: (function($,undefined) { "use strict"; ... })(jQuery); Note the undefined. That's because undefined is not a literal but a variable in JavaScript and can be assigned to anything. This way I ensure that undefined is really undefined and "x === undefined" works. But I digress.
- yuchi 13y agoAbout `undefined`, that’s not true anymore in ES5, btw.
- uxp 13y agoIt has nothing to do with jQuery, or anything else. (function() {})(); is a pretty standard Javascript pattern to execute an anonymous function immediately at evaluation. Because javascript has lexical scoping at the function, your use of "use strict"; and any var-prepended variables won't be hoisted up the prototype chain, potentially becoming globals. The ability to pass in a global as a local variable is simply a convenience. The global is available inside the closure anyways. It's a global after all. My point was, the battle over the dollar sign single character variable name is stupid.
- iM8t 13y agoIs it just me, or is their analytics JS file down?
- dudus 13y agoMaybe you have a plugin blocking it.
- a-l-c-o 13y agoLike you I got a 404. Then I remembered I blacklist this adress in /etc/hosts : 0.0.0.0 google-analytics.com Maybe you forgot you do too ?
- iM8t 13y agoYeah, I do. How forgetful of me. Thanks!
- smokinjoe 13y agoMaybe a little off topic, but what's the purpose for that? Does it make websites that use google analytics unable to track your visit?
- xtreme 13y agoEverytime you visit a GA enabled site, it sends back some information to the Google servers including url, referrer, time spent etc. Google can use this build up a history of websites you (this is not linked to your Google account, more like an unique id) frequent and show targeted advertisements.
- Dylan16807 13y agoHow does lack of IP turn into a 404?
- enduser 13y agoIf you are running a web server on your own computer that does not have a resource at that URI. 0.0.0.0 is a magic number that means any local network interface.
- judk 13y agoIt's been a few decades.. Maybe time for some new community jokes?
- pepon 13y agoAgreed...
- timothya 13y agoIt's tricky to tell exactly what's happening because the code is obfuscated through compilation, but as best I can tell, it's using the `answer` value to prevent another global from making it seem like the Analytics code has already been initialized. There is a JavaScript object representing all of the Google Analytics state and functions. When this object is set up, they add the property "answer = 42" to it. Then, before making this object globally accessible at `window.ga`, they double check that `window.ga` does not yet exist or that `window.ga.answer` does not equal 42. If it already equals 42, then the initialization must have already happened (maybe the Analytics code was included twice?), and so it doesn't proceed to clobber that already-initialized global Analytics state. Checking that the `window.ga` variable doesn't exist is not quite enough, since other JavaScript on the page may have set that property for some reason (of course, this logic wouldn't work if other code on the page had simple set `window.ga.answer = 42`, but that's unlikely to happen by accident). As long as it looks like the initialization hasn't already run, then it goes ahead and does the initialization and makes the result globally accessible at that point. tl;dr: It's not just a joke; it's actually used to make it less likely that other JavaScript on the page hasn't created a global variable called `ga` which may otherwise prevent the Analytics code from running.
- mar1 13y agoHere's an useful website if you want to make the code more readable: http://jsbeautifier.org/ http://jsbeautifier.org/
- timothya 13y agoChrome also has a button[0] to do this automatically in the Developer Tools, which is what I used when I wrote the initial comment. [0]: https://developers.google.com/chrome-developer-tools/docs/javascript-debugging#pretty-print https://developers.google.com/chrome-developer-tools/docs/ja...
- deleted 13y ago[deleted]
- Joshu42 13y agoNice finding ! And it's so true ! 42 is the answer to everything ;) Even to check an instantiation ... $.answer = 42; [...] $.N = function () { var a = O[gb]; if (!a || 42 != a.answer) { [...] O[gb] = $; [...] } }; $.N();
- dkersten 13y ago42 is the answer to everything That's not really what the Hitchhikers Guide to the Galaxy said - rather, 42 is the answer to the ultimate question of life, the universe and everything. But since we don't know what the question is... Very different from the answer to everything.
- currysausage 13y agoSlightly OT: What is the background for allowing $ to be used in ECMAScript identifiers? I imagine there could be some compatibility background.