George Reith
George Reith

Reputation: 13476

Uncaught SyntaxError: Unexpected token (

I am receiving the following error:

Uncaught SyntaxError: Unexpected token ( /timeline/scripts/collections/events.js?bust=1365755363650:1

Here's /timeline/scripts/collections/events.js:

function () {
    return Backbone.Collection.extend({
        model: Event

    ,   parse: function(data) {
            var parsed = [];
            $(data).find('Event').each(function(index) {
                parsed.push({
                    title: $(this).find('title').text()
                ,   date: $(this).find('date').text()
                ,   content: $(this).find('content').text()
                });
            });
            return parsed;
        }

    ,   fetch: function(options) {
            options = options || {};
            options.dataType = "xml";
            Backbone.Collection.prototype.fetch.call(this, options);
        }
    });
};

For some reason it is choking on function () { but I can't work out why. This is the entire document. Can anyone explain what is wrong with this?

Upvotes: 0

Views: 1106

Answers (3)

Michael Geary
Michael Geary

Reputation: 28850

When one syntax checker doesn't give a useful error message, try another one.

I'm usually a fan of the Chrome developer tools, but in this case Chrome doesn't give a very good error message. So I tried pasting your code into Firefox, and it was much more helpful:

SyntaxError: function statement requires a name
    function () {

I also got that same error message by pasting your code into Komodo which has live syntax checking while you edit. (Not surprising the message is the same since Komodo is based on Firefox.)

It pays to try different tools when one isn't helping.

Upvotes: 0

Loamhoof
Loamhoof

Reputation: 8293

You cannot declare an anonymous function without calling it.

Upvotes: 0

Quentin
Quentin

Reputation: 943108

You have a function declaration, not a function expression. Function declarations must have names.

function foo () {
    return Backbone.Collection.extend({

Upvotes: 1

Related Questions