JSLint消息:未使用的变量 [英] JSLint message: Unused variables

查看:112
本文介绍了JSLint消息:未使用的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这种情况下,如果JSLint抱怨"i"是未使用的变量,该怎么办:

what can I do if JSLint complains about "i" being an unused variable in such a scenario:

var items = "<option selected></option>";
$.each(data, function (i, item) {
    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
});

(i,item)是参数的必需顺序,我仅使用"item".

(i, item) is the required order of parameters and I'm only using "item".

除了容忍未使用的变量或重写$ .each以使用索引之外,还有其他解决方案吗,我都不想这样做?

Is there any other solution than tolerating unused variables or rewriting the $.each to use the index, both solutions which I would prefer not to do?

谢谢.

更新:非常感谢所有建议,但是这段代码只是一个示例,向您展示我的意思,并且我希望看到一个通用的解决方案(如果有的话).谢谢.

Update: I appreciate all the suggestions but this code is simply an example to show you what I mean and I'm interested to see a general solution, if there's any. Thanks.

推荐答案

尝试:

var items = "<option selected></option>";
/*jslint unparam: true*/
$.each(data, function (i, item) {
    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
});
/*jslint unparam: false*/  // so that you still get warnings from other functions

这篇关于JSLint消息:未使用的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆