Skip to content

Instantly share code, notes, and snippets.

@dey-dey
Created July 6, 2012 19:03
Show Gist options
  • Save dey-dey/3062131 to your computer and use it in GitHub Desktop.
Save dey-dey/3062131 to your computer and use it in GitHub Desktop.
Backbone View Inheritance
var BaseView = Marionette.ItemView.extend({
tagName: 'li',
className: "class1",
template: template,
events: {
"click": "func1",
"keyup .input": "func2"
},
initialize: function( options ){
//set bindings for functions
_.bindAll(this, 'func1', 'func2');
//logs only this class events
console.log('childview', this.events);
},
func1: function(){
//do something
},
func2: function(){
//do something
}
})
var ChildView = BaseView.extend({
tagName: 'span',
className: "class2",
template: template,
events: {
"click": "func2",
"keyup .input": "func3"
},
initialize: function( options ){
//inherit prototype bindings by running its intialize function
Transaction.prototype.intialize.apply(this, arguments);
//prototype bindings added to this
_.bindAll(this, 'func2', 'func3');
//log shows this childview events as well as base view events
console.log('childview', this.events);
},
func2: function(){
//call prototype function in this context
Transaction.prototype.func2.apply(this, arguments);
//run this function
},
func3: function(){
//do something
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment