Created
October 18, 2012 03:09
-
-
Save lyuehh/3909659 to your computer and use it in GitHub Desktop.
extend a view in 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
// demo: http://jsfiddle.net/ShUW2/2/ | |
var P = Backbone.View.extend({ | |
events: { | |
'click p': 'p', | |
'change #a': 'change', | |
'click #s': 'click' | |
}, | |
p: function (e) { | |
alert('clicked the p'); | |
}, | |
change: function (e) { | |
var $el = $(e.target); | |
console.log($el.val()); | |
}, | |
click: function () { | |
alert('click in p..'); | |
} | |
}); | |
var p1 = new P({el: '#parent'}); | |
var C = P.extend({ | |
initialize: function () { | |
P.prototype.initialize.apply(this); | |
}, | |
p: function (e) { | |
alert('clicked the p in child'); | |
} | |
}); | |
var c1 = new C({el: '#child'}); |
demo: http://jsfiddle.net/ShUW2/3/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
extends events also: