public
Created

more than just backbone constructs

  • Download Gist
1-appview.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11
AppView = Backbone.View.extend({
 
initialize: function(){
this.router = new AppRouter();
this.collection = new MyCollection();
this.someView = new SomeView();
this.someView.render();
Backbone.history.start();
}
 
});
2-app.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
function MyApp(){
var router = new MyRouter();
var myCollection = new MyCollection();
var someView = new SomeView({collection: myCollection});
this.start = function(initialModels){
myCollection.reset(initialModels);
someView.render();
Backbone.history.start();
}
}
 
var someModels = [...];
 
new MyApp().start(someModels);
3-events.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13
// simple, object literal event thingy
var myThingy = _.extend({}, Backbone.Events);
 
// or a full object
function MyThingy(){
_.extend(MyThingy.prototype, Backbone.Events);
 
// other stuff here
}
var myThingy = new myThingy();
 
// use events!
myThingy.trigger("some:event");

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.