Skip to content

Instantly share code, notes, and snippets.

@TheBox193
Last active August 29, 2015 14:18
Show Gist options
  • Save TheBox193/edb66f9e76d47d120bee to your computer and use it in GitHub Desktop.
Save TheBox193/edb66f9e76d47d120bee to your computer and use it in GitHub Desktop.
Clean Backbone
Collection1 = Backbone.Collection.extend({
initialize: function(models, options){
// bad, causes things to crash if options.that doesn’t get passed.
this.doSomethingWithThat(options.that);
}
});
// Crashes since 'that' is not set
collection1 = new Collection1();
Collection2 = Backbone.Collection.extend({
initialize: function(models, options){
// good, causes things to crash if options.that doesn’t get passed.
var that = options.that || 'defaultThatValue';
this.doSomethingWithThat(options.that);
}
});
// Success providing doSomethingWithThat supports the defualt
collection2 = new Collection2();
View1 = Backbone.View.extend({
sampleFunction: function () {}
});
View2 = Backbone.View.extend({
sampleFunction: function () {
// Wrong since View1 is not the prototype of View2
View1.prototype.sampleFunction();
}
});
View3 = View1.extend({
sampleFunction: function () {
// Right since View1 is the prototype of View3
View1.prototype.sampleFunction();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment