【问题标题】:jshint expected an assignment errorjshint 预期分配错误
【发布时间】:2014-06-04 19:26:44
【问题描述】:
        // BAR CHART
        if (sparklineType == 'bar') {

                barColor = $this.data('sparkline-bar-color') || $this.css('color') || '#0000f0',
                sparklineHeight = $this.data('sparkline-height') || '26px',
                sparklineBarWidth = $this.data('sparkline-barwidth') || 5,
                sparklineBarSpacing = $this.data('sparkline-barspacing') || 2,
                sparklineNegBarColor = $this.data('sparkline-negbar-color') || '#A90329',
                sparklineStackedColor = $this.data('sparkline-barstacked-color') || ["#A90329", "#0099c6", "#98AA56", "#da532c", "#4490B1", "#6E9461", "#990099", "#B4CAD3"];

            $this.sparkline('html', {
                barColor : barColor,
                type : sparklineType,
                height : sparklineHeight,
                barWidth : sparklineBarWidth,
                barSpacing : sparklineBarSpacing,
                stackedBarColor : sparklineStackedColor,
                negBarColor : sparklineNegBarColor,
                zeroAxis : 'false'
            });

        }

对于上面 JSHINT 中的代码,我收到以下错误消息:

“期待一个赋值或函数调用,但看到了一个表达式”

谁能告诉我如何解决这个问题?

谢谢!

【问题讨论】:

  • jsfiddle.net/GaurangTandon/u3R8t 说你的 JS 完全有效。
  • 这个错误的存在可能是因为这个表达式之前的一些其他代码有关。你能再给我们一点吗?
  • @rescuecreative 绝对是,请参见上文:)
  • 我的第一个想法是,这可能与您使用逗号分隔多个分配但开头没有 var 关键字的事实有关。尝试将它们更改为分号,看看是否可以。

标签: javascript performance-testing jshint grunt-contrib-jshint


【解决方案1】:

这个错误(逗号)

barColor = $this.data('sparkline-bar-color') || $this.css('color') || '#0000f0',
sparklineHeight = $this.data('sparkline-height') || '26px',
sparklineBarWidth = $this.data('sparkline-barwidth') || 5,
sparklineBarSpacing = $this.data('sparkline-barspacing') || 2,
sparklineNegBarColor = $this.data('sparkline-negbar-color') || '#A90329',
sparklineStackedColor = $this.data('sparkline-barstacked-color') || ["#A90329", "#0099c6", "#98AA56", "#da532c", "#4490B1", "#6E9461", "#990099", "#B4CAD3"];

试试这个(分号 - ;)

barColor = $this.data('sparkline-bar-color') || $this.css('color') || '#0000f0';
sparklineHeight = $this.data('sparkline-height') || '26px';
sparklineBarWidth = $this.data('sparkline-barwidth') || 5;
sparklineBarSpacing = $this.data('sparkline-barspacing') || 2;
sparklineNegBarColor = $this.data('sparkline-negbar-color') || '#A90329';
sparklineStackedColor = $this.data('sparkline-barstacked-color') || ["#A90329", "#0099c6", "#98AA56", "#da532c", "#4490B1", "#6E9461", "#990099", "#B4CAD3"];

【讨论】:

  • Yewww 应该已经看到了!谢谢! :)
【解决方案2】:

布尔表达式依赖于 null 或 undefined 的“虚假性”来决定是分配 $this.data 还是数组字面量。我的猜测是 jshint 希望您明确分配值,以便您可以明确检查 $this.data 是否为 null 或未定义,然后进行相应的分配。

【讨论】:

    猜你喜欢
    • 2020-11-16
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多