jshint期望分配错误

时间:2014-04-20 17:20:55

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

        // 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中的上述代码,我收到以下错误消息:

  

“预期分配或函数调用,而是看到表达式”

有人可以告诉我如何解决这个问题吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

布尔表达式依赖于" falsiness" null或undefined,用于决定是否分配$ this.data或数组文字。我的猜测是,jshint希望你明确指定一个值,这样你就可以明确地检查$ this.data为null或undefined然后相应地分配。

答案 1 :(得分:0)

这是错误的(逗号)

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"];