0

My code looks like this:

$.extend($.fn.dataTableExt.afnSortData, {
    'dom-text': function (oSettings, iColumn) {
        var aData = [];
        $('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
            aData.push(this.value);
        });
        return aData;
    },
    'dom-data-rk': function (oSettings, iColumn) {
        var aData = [];
        $('td:eq(' + iColumn + ')', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
            aData.push($(this).attr('data-rk'));
        });
        return aData;
    }
});

I used JSLint and it came up with an error:

Warning 21  JS Lint: Unexpected dangling '_' in '_fnGetTrNodes'.

Can someone explain what this means? I don't understand the error message at all :-(

James Allardice
  • 164,175
  • 21
  • 332
  • 312
Alan2
  • 23,493
  • 79
  • 256
  • 450

4 Answers4

4

JSLint simply doesn't like identifiers to begin with an underscore character. Change the identifier and the warning will go away, or add the following directive to the top of the file:

/*jslint nomen: true */

The reason it doesn't like them is that people often use it to indicate a "private" variable, but doesn't actually change the behaviour of the variable.

James Allardice
  • 164,175
  • 21
  • 332
  • 312
2

Do not use _ (underbar) as the first character of a name. It is sometimes used to indicate privacy, but it does not actually provide privacy. If privacy is important, use the forms that provide private members. Avoid conventions that demonstrate a lack of competence.

more about code conventions used by JSLint here

lupatus
  • 4,208
  • 17
  • 19
1

You can simply set "tolerate dangling _ in identifiers" to true to ignore this error.

Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
1

Well, JSlint doesn't like a variable name that begins with an underscore (_).


It is better to use JShint.com instead of JSlint. It's a fork of JSlint and provide you more options of configuration and doesn't show stupid errors like this. https://stackoverflow.com/a/10763615/1149495

Community
  • 1
  • 1
Wouter J
  • 41,455
  • 15
  • 107
  • 112