javascript - 关于三目运算 ESlint报错
伊谢尔伦
伊谢尔伦 2017-04-11 12:36:48
0
3
405
var checkboxShow = function checkboxShow(first, second) { var $feedType = $webForm.find('[data-rule=fade-type]'); var $checkbox = $feedType.find('input[type = checkbox]'); var i; for (i = 0; i < arguments.length; i++) { arguments[i] === 0 ? $checkbox.eq(i).prop('disabled', true) : $checkbox.eq(i).prop('checked', true); } };

这个函数是要根据参数判断两个复选框是选择还是禁用

这么写三目运算符有什么问题啊?ESlint报错no-unused-expressions,明明生效了,但是报错了,应该怎么写?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

répondre à tous (3)
大家讲道理

要么用if-else,要么用void运算符:

void(arguments[i] === 0 ? $checkbox.eq(i).prop('disabled', true) : $checkbox.eq(i).prop('checked', true));
    迷茫

    首先我记得 三目表达式 是 C++里面的叫法 ;js里面这个叫 三元表达式。 为什么会出错呢?其他的不说,我就觉得你的写法很奇怪var checkboxShow = function checkboxShow(first, second) {};为什么要这样写呀?? 你都有个函数名了 checkboxShow ;然后 又把它赋给一个变量!直接这样写var checkboxShow = function (first, second) {};不就可以了,或者直接写function checkboxShow(first, second) {};。具体你再看看你的代码,是不是要定义个变量接受函数返回值什么的。

      黄舟

      这跟三元表达式没有关系,关于 unused expression,请见:http://eslint.org/docs/rules/...

      觉得没用就直接关闭这条规则吧

        Derniers téléchargements
        Plus>
        effets Web
        Code source du site Web
        Matériel du site Web
        Modèle frontal
        À propos de nous Clause de non-responsabilité Sitemap
        Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!