Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
奇怪的javascript语法错误_Javascript_Angularjs - Fatal编程技术网

奇怪的javascript语法错误

奇怪的javascript语法错误,javascript,angularjs,Javascript,Angularjs,在Firefox中,我收到了一个奇怪的语法错误,因为这不是一个微不足道的错误,我想在这里发布一个有趣的语法错误,因为我不知道它正在发生 是否应将此作为错误报告归档 我在这里测试了一些脚本: 它给了我一个语法错误语法错误:第5行的标签无效 app.directive("alertable", function() { return { restrict : "A", link: function(scope, element, attrs)

在Firefox中,我收到了一个奇怪的语法错误,因为这不是一个微不足道的错误,我想在这里发布一个有趣的语法错误,因为我不知道它正在发生

是否应将此作为错误报告归档

我在这里测试了一些脚本:

它给了我一个语法错误<代码>语法错误:第5行的标签无效

app.directive("alertable", function()
{
    return 
    {
        restrict : "A",
        link: function(scope, element, attrs) 
        {
            element.bind("click", function() 
            {
                alert(attrs.message);
            });
        }
    };
});
而这个,不要:

app.directive("alertable", function()
{
    return { // fix???
        restrict : "A",
        link: function(scope, element, attrs) 
        {
            element.bind("click", function() 
            {
                alert(attrs.message);
            });
        }
    };
});

这种行为是故意的

Javascript中的分号是可选的。()
解析器在
返回
行之后插入一个隐式分号,并假定
{
开始一个代码块。(如
if
for
之后)

该代码块中的第一行实际上不是有效代码,因此会出现该错误

之所以会发生这种情况,是因为
return
是一条有操作数和无操作数的有效语句

类似地,代码

return
4;

解析为
return;4;

感谢您的启发,我以前从未听说过“ASI”。很高兴知道。现在我将编写更好的代码。