Live data from Hacker News

$.answer=42

google-analytics.com

21–27 of 27 posts

Re: $.answer=42

#21
post #12
post #4

Is it just me, or is their analytics JS file down?

Like 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 ?

Maybe a little off topic, but what's the purpose for that? Does it make websites that use google analytics unable to track your visit?

Re: $.answer=42

#22
post #19
post #10

Earlier quoted context omitted.

var $=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.

The 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);

Yes, 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.

Re: $.answer=42

#23
post #12
post #4

Is it just me, or is their analytics JS file down?

Like 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 ?

How does lack of IP turn into a 404?

Re: $.answer=42

#24
post #12

Earlier quoted context omitted.

Like 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 ?

How does lack of IP turn into a 404?

If 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.

Re: $.answer=42

#25
post #22
post #19

Earlier quoted context omitted.

The 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);

Yes, 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.

About `undefined`, that’s not true anymore in ES5, btw.

Re: $.answer=42

#26
post #12

Earlier quoted context omitted.

Like 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 ?

Maybe a little off topic, but what's the purpose for that? Does it make websites that use google analytics unable to track your visit?

Everytime 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.

Re: $.answer=42

#27
post #22
post #19

Earlier quoted context omitted.

The 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);

Yes, 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.

It 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.

Post reply on HN