Reputation: 1516
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?
Upvotes: 4
Views: 2756
Reputation: 754525
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;
})();
};
Upvotes: 3
Reputation: 992707
If 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;
})();
}
Upvotes: 4