I started fiddling around with Dojo.js and came across a thing I don't understand.
I'm trying to create my own widget. The widget would be really simple - it would just query all images on the page and make them listen for a 'click' event. Each click would increase the widget's counter attribute by 1.
Here's my take on it:
define(
[
"dojo/_base/declare",
"dojo/query",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/text!myProject/folder/myWidgetTemplate.html",
],
function(declare, query, _WidgetBase, _TemplatedMixin, template) {
declare("MyWidget", [_WidgetBase, _TemplatedMixin], {
templateString: template,
counter: 0,
onClick: function(evt) {
this.counter++;
console.log(this.counter);
},
postCreate: function() {
query("img").on("click", this.onClick);
}
});
}
);
The widget initializes and I indeed can click on images, but the console always returns undefined. It seems that I'm missing some core aspect about how the dojo/on module works. Could somebody explain to me what exactly happens in my code?