Jslint错误:预期赋值或函数

时间:2014-02-28 16:43:30

标签: jquery jslint

我在尝试使用下面的脚本时从jslint收到2个错误,违规行是:

rowDivs = new Array(); 数组文字符号[]更可取。现在我尝试将其更改为Array([])它会删除错误但不确定这是否正确?

topPosition = 0; 期望一个赋值或函数调用,而是看到一个表达式

有人有任何想法吗?

     equalheight = function (container) {

        var currentTallest = 0,
        currentRowStart = 0,
        rowDivs = new Array[];
        $el,
        topPosition = 0;
        $(container).each(function () {

        el = $(this);
        $($el).height('auto');
        topPostion = $el.position().top;

            if (currentRowStart != topPostion) {
                for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
                    rowDivs[currentDiv].height(currentTallest);
                }
                rowDivs.length = 0; // empty the array
                currentRowStart = topPostion;
                currentTallest = $el.height();
                rowDivs.push($el);
            } else {
                rowDivs.push($el);
                currentTallest = (currentTallest < $el.height()) ? ($el.height()) :     (currentTallest);
            }
            for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
                rowDivs[currentDiv].height(currentTallest);
            }
        });
    };

    $(window).load(function () { equalheight('.equal'); });
    $(window).resize(function () { equalheight('.equal'); });

1 个答案:

答案 0 :(得分:3)

你的语法错了,你有一个额外的分号:

var currentTallest = 0,
    currentRowStart = 0,
    rowDivs = [],
    $el,
    topPosition = 0;