0

In this SO question, the answerer uses an underscore on line 3. If it were simply the start of a variable name, I'd be good with that. But what does _(row) mean?

Community
  • 1
  • 1
Phillip Senn
  • 46,771
  • 90
  • 257
  • 373

2 Answers2

4

It is the start of a variable name. It is also the end of a variable name. The variable (which has a function assigned to it) is _. The question references underscore.js, which provides it.

Try, for example:

function _() { 
    alert('underscore!'); 
};
console.log(typeof _);
console.log(_);
_();​

Welcome to the wonderful world of completely unintuative variable names that are used because they are short and not alphanumeric. See also $, beloved of Prototype, jQuery and Mootools. In counterpoint, see Self-documenting (code) on Wikipedia.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks Quentin! I've heard of the underscore library in passing, but have never taken the time to read anything about it. – Phillip Senn May 02 '12 at 21:18
3

The _ is underscore.js. _ is a variable, it's a function, so you can do _(rows).

In JavaScript, you can name variables whatever you want. Such as $ (jQuery) and _.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • OK, thanks Rocket! If I have jQuery loaded, I don't think I need underscore. It looks like I can process it with the jQuery each command. – Phillip Senn May 02 '12 at 21:19