admin管理员组文章数量:1415460
If the following is passed into Google code closure:
return (function() {
return true;
})();
it says there is a parsing error due to invalid syntax. What could be the problem?
If the following is passed into Google code closure:
return (function() {
return true;
})();
it says there is a parsing error due to invalid syntax. What could be the problem?
Share Improve this question edited Mar 19, 2012 at 19:48 user166390 asked Mar 19, 2012 at 19:31 cubetwo1729cubetwo1729 1,5161 gold badge11 silver badges18 bronze badges 1-
1
Note that you are not returning an anonymous function but creating and calling an anonymous function. So this statement is equivalent to just
return true;
. – maerics Commented Mar 19, 2012 at 19:44
2 Answers
Reset to default 4If that is your entire code, the problem is that you can't have a return
statement (the first one) outside a function definition. Try:
function foo() {
return (function() {
return true;
})();
}
The problem appears to be that you are using return
as a top level construct (outside of any function body). You need to wrap it inside a context in which return
is valid:
var example = function () {
return (function() {
return true;
})();
};
本文标签:
版权声明:本文标题:javascript - Why does this cause an "invalid syntax" error with Google's Closure Compiler? - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745160945a2645437.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论