Last active
August 29, 2015 14:18
-
-
Save TheBox193/edb66f9e76d47d120bee to your computer and use it in GitHub Desktop.
Clean Backbone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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