2

From jquery.ui.autocomplete.js:

_renderMenu: function( ul, items ) {
    var self = this;
    $.each( items, function( index, item ) {
        self._renderItem( ul, item );
    });
},
sinemetu1
  • 1,716
  • 1
  • 13
  • 24
user784637
  • 13,012
  • 31
  • 83
  • 144

4 Answers4

7

Underscore prefixes in javascript are mostly used to signify "private" functions, properties etc. I.e., functions and properties that are used internally and should not be accessed from outside the library/plugin.

And yes, as nnnnnn says, the important word there is "should", as in:

  • It can be accessed - Javascript won't do anything to stop you - it's just a naming convention.
  • It would be ill-advised to actually do it. Mostly, the author will have good reason to indicate internal use. E.g. a property which may not behave as you think (for example cached values that won't be available in all cases); a function may depend on specific internal state or have side effects on that state; etc.
JimmiTh
  • 7,229
  • 3
  • 30
  • 46
  • Where "should not be accessed" is the key phrase and applies to people writing code because it is a naming convention only that has no meaning to the JavaScript engine... – nnnnnn Feb 05 '12 at 04:22
4

Usually, people like to use _ to denote the variable/function to be private, but _ has no special meaning in JavaScript.

Grace Shao
  • 4,917
  • 4
  • 26
  • 51
0

It doesn't mean anything technically but usually the writer intends it to make it as protected (internal method)

ysrb
  • 6,563
  • 2
  • 27
  • 29
0

I'm not sure where I heard this, looking for documentation as I write this, but I believe vars that start with underscore are usually denoting a private scope.

For reference looks like it's a C thing that other programmers implemented.

sinemetu1
  • 1,716
  • 1
  • 13
  • 24