I see many tutorials initializing Backbone Models/Views after jQuery loaded. Why is that? Can’t you define it before?
For example link
jQuery ->
class ListView extends Backbone.View
el: $ 'body'
initialize: ->
_.bindAll @
@counter = 0
@render()
You could define the classes before document loads and initialize views/models after document loads?
Also I see Models/Views defined under window why is that?
window.TodoView = Backbone.View.extend
...
Why initialize a View after jQuery?
From the main Backbone page;
[Emphasis mine]
So that’s the dependency right there.
Models/Views defined under
window?It simplifies these little tutorial examples – everything has access to
window, so it makes a useful (if messy) dumping ground for globals (ctors, variables, functions, etc).IMO, for larger (non-demo) projects, you should be using something like RequireJS.