My app is throwing an Uncaught SyntaxError: Unexpected token .
in the following files:
Uncaught SyntaxError: Unexpected token . Tweet.js:2
Uncaught SyntaxError: Unexpected token . Timeline.js:2
Uncaught SyntaxError: Unexpected token . TimelineView.js:2
Uncaught SyntaxError: Unexpected token . app.js:2
However, when I refer to the files, to checkout the lines in question, I see no errors:
Tweet.js:
var com = com || {}
, com.apress = com.apress || {}
, com.apress.model = com.apress.model || {}
, com.apress.model.Tweet = Backbone.Model.extend({});
Timeline.js:
var com = com || {}
, com.apress = com.apress || {}
, com.apress.collection = com.apress.collection || {}
[...]
TimelineView.js:
var com = com || {}
, com.apress = com.apress || {}
, com.apress.view = com.apress.view || {}
[...]
app.js:
var com = com || {}
, com.apress = com.apress || {}
, com.apress.view = com.apress.view || {}
, com.apress.view.TimelineView = Backbone.View.extend({
});
$(function() {
var timelineView = new com.apress.view.TimelineView();
});
I consistently get these errors and resolve them without ever understanding how I resolved them. What causes Uncaught SyntaxError: Unexpected token .
errors and how do I resolve the ones above?
.
is not a valid character in a variable name, so you can't do
var com.apress = ... ;
Instead of using a variable declaration statement with multiple declarations, you should have a single declaration and simple assignments:
var com = com || {};
com.apress = com.apress || {};
com.apress.view = com.apress.view || {};
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments