最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JS Lint: Unexpected dangling '_' in '_fnGetTrNodes' - Stack Overflow

programmeradmin1浏览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 :-(

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 :-(

Share Improve this question edited Sep 28, 2012 at 12:55 James Allardice 166k22 gold badges334 silver badges315 bronze badges asked Sep 28, 2012 at 12:37 Alan2Alan2 24.7k86 gold badges276 silver badges481 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 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.

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

more about code conventions used by JSLint here

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

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


It is better to use JShint. 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./a/10763615/1149495

发布评论

评论列表(0)

  1. 暂无评论