Slide 9
Slide 9 text
define([
'dijit/_WidgetBase',
'dijit/_TemplatedMixin',
'text!./my-template.html'
], function(_Widget, _Templated, tmpl) {
return dojo.declare([ _Widget, _Templated ], {
templateString : tmpl,
postMixInProperties : function() {
this.clicks = 0;
},
postCreate : function() {
this.connect(this.buttonElement, 'click', '_onButtonClick');
},
_onButtonClick : function(e) {
e.preventDefault();
console.log(++this.clicks);
this.onButtonClick(this.clicks);
},
onButtonClick : function(clickCount) { }
});
});
Friday, June 1, 12
dojo’s widgets also provide `this.connect`, which handles standard event binding *and*
binding to arbitrary methods of arbitrary objects -- all with teardown that avoids memory
leaks
of course, backbone’s standard event delegation stuff takes care of this for delegate-able
DOM events, but it’s a different story when you’re binding to models/collections