News for hackers. Stuff that matters.
Re:$.answer=42 by dm2 on Saturday April 12, 2014 @01:40PM (#7578514)
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.

Re:$.answer=42 by uxp on Saturday April 12, 2014 @03:16PM (#7578836)
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);
Re:$.answer=42 by panzi on Saturday April 12, 2014 @04:41PM (#7579115)
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 by uxp on Saturday April 12, 2014 @09:13PM (#7579798)
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.

Re:$.answer=42 by yuchi on Saturday April 12, 2014 @05:17PM (#7579246)
About `undefined`, that’s not true anymore in ES5, btw.