What is the reason behind JSLint saying there are “too many var statements”

后端 未结 7 1142
时光说笑
时光说笑 2020-12-13 12:06

JSLint (with the onevar flag turned on) is flagging some javascript code that I have with the following:

Problem at line 5 character 15: Too many var statements.         


        
7条回答
  •  感动是毒
    2020-12-13 12:52

    The idea is that you should use an object instead of individual vars. So where you have got:

    var x = arg + 1,
        y = cache.GetItem('xyz');
    

    Change it to:

    var dimensions = {};
    dimensions.x = arg + 1;
    dimensons.y = cache.GetItem('xyz');
    dimensions.request = ...
    

    You can then access these variables through the object, its neater to have one object per function to contain that functions variables. Then you won't get the warning.

提交回复
热议问题