JS Lint: Unexpected dangling '_' in '_fnGetTrNodes'

爱⌒轻易说出口 提交于 2019-12-25 04:50:11

问题


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


回答1:


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.




回答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




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/12640173/js-lint-unexpected-dangling-in-fngettrnodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!