You have a new line after return
, so according to the rules for Automatic Semicolon Insertion (ASI), it is treated as having ;
in the end, so the return
statement ends there.
Therefore, according to the parser you have the following unrelated code afterwards:
{
create: function(table, initialSortedColumn, customDataAccessors)
{
var sorter = Object.create(sorterPrototype);
sorter.init(table, initialSortedColumn, customDataAccessors);
return sorter;
}
};
This is interpreted as a code block starting with {
on the first line and finishing with };
on the last line. Inside it, you have a label called create
and a function statement with no name of the function. Having nameless function statements is illegal, hence why you get the error.
In effect, you have according to the JavaScript parsing rules, the following problematic code:
function(/* parameters */) { /* body */ }
In reality, your top level function will always return undefined
due to ASI and the code after will never be reached but you still get an error from parsing it.
What you want to do is the following:
return {
create: function(table, initialSortedColumn, customDataAccessors)
{
var sorter = Object.create(sorterPrototype);
sorter.init(table, initialSortedColumn, customDataAccessors);
return sorter;
}
};
This way you are returning an object with a property called create
an a function assigned to it.