gpt4 book ai didi

javascript - 显示模块模式语法错误

转载 作者:行者123 更新时间:2023-11-30 08:07:00 25 4
gpt4 key购买 nike

也许这个问题没有太大的建设性,但似乎我可以弄清楚为什么会出现此语法错误:

 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 ;
};

};

最佳答案

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

        return
{
computeTotalPrice : computeTotalPrice,
HightLightChangedPrices : HightLightChangedPrices
};

应该是

        return {
computeTotalPrice : computeTotalPrice,
HightLightChangedPrices : HightLightChangedPrices
};

问题在于“限制制作”。 http://es5.github.io/#x5.1.6

If the phrase “[no LineTerminator here]” appears in the right-hand side of a production of the syntactic grammar, it indicates that the production is a restricted production: it may not be used if a LineTerminator occurs in the input stream at the indicated position. For example, the production:

ReturnStatement :
    return [no LineTerminator here] Expressionopt ;

JavaScript 解析器看到您的代码并解析第一行,返回,然后是行终止符,所以它 inserts a semicolon然后继续下一行。然后它看到一个 { 并将其解释为自顶层 Expression Statement 以来的语句 block 的开始不能以 {:

开头

ExpressionStatement :
    [lookahead ∉ {{, function}] Expression ;

在 block 内,

 computeTotalPrice : computeTotalPrice, HightLightChangedPrices

是一个有效的 labelled statement , 但语句不能有效地后跟 : 这就是为什么它在那里要求分号。

关于javascript - 显示模块模式语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16652296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com