显示模块模式语法错误

Vla*_*žić 1 javascript

也许这个问题不太具有建设性,但似乎我可以弄清楚为什么我得到这个语法错误:

 var operations = function () {
            function computeTotalPrice(elem) {
                var totalpriceafter = 0;
                 $(".totalForProductNotDeleted").each(function () {
                    var pp = parseFloat($(this).html().toString().replace(",", "."));
                    totalpriceafter += pp;
                });
                return totalpriceafter;
            };
           function HightLightChangedPrices(elem) {
                elem.parent().parent().parent().find(".totalForProduct").effect("highlight");
                $("#totalPrice").effect("highlight");
            };
            return
            {
                computeTotalPrice : computeTotalPrice,
                HightLightChangedPrices : HightLightChangedPrices / I get expected ; 
            };

        };
Run Code Online (Sandbox Code Playgroud)

Mik*_*uel 6

return 必须在同一行后面跟一个值.

        return
        {
            computeTotalPrice : computeTotalPrice,
            HightLightChangedPrices : HightLightChangedPrices 
        };
Run Code Online (Sandbox Code Playgroud)

应该

        return {
            computeTotalPrice : computeTotalPrice,
            HightLightChangedPrices : HightLightChangedPrices 
        };
Run Code Online (Sandbox Code Playgroud)

问题在于"限制生产". http://es5.github.io/#x5.1.6

如果短语"[此处没有LineTerminator]"出现在句法语法生成的右侧,则表示生产是限制生产:如果LineTerminator出现在输入流中,则可能无法使用它.指示的位置.例如,制作:

ReturnStatement:
    return [此处没有LineTerminator] 表达式选择 ;

JavaScript解析器看到你的代码并解析第一行,return然后解析行终止符,所以它插入一个分号然后继续到下一行.然后它看到a {并将其解释为语句块的开头,因为顶级表达式语句不能以{:

ExpressionStatement:
    [lookahead∉{ {,function}]表达式 ;

在街区内

 computeTotalPrice : computeTotalPrice, HightLightChangedPrices
Run Code Online (Sandbox Code Playgroud)

是一个有效的标签声明,但声明不能有效地跟随,:这就是为什么它要求在那里分号.