I'm using Dojo framework to help me in my Javascript development with cross browsing DOM manipulation and event managing.
For this last I was hoping to use custom event dispatching between objects. But I don't find anything on this. I read about subscribe/publish, but it not exactly what I want.
Here is what I'd want to do :
var myObject = new CustomObject();
dojo.connect(myObject, 'onCustomEvent', function(argument) {
console.log('custom event fired with argument : ' + argument);
});
var CustomObject = (function() {
CustomObject = function() {
// Something which should look like this
dojo.dispatch(this, 'onCustomEvent', argument);
};
}) ();
Anyone could help me ?
Thanks.
I normally do it this way: (tested with Dojo 1.3.2)
dojo.declare("CustomObject", null, {
randomFunction: function() {
// do some processing
// raise event
this.onCustomEvent('Random Argument');
},
onCustomEvent: function(arg) {
}
});
var myObject = new CustomObject();
dojo.connect(myObject, 'onCustomEvent', function(argument) {
console.log('custom event fired with argument : ' + argument);
});
// invoke the function which will raise the custom event
myObject.randomFunction();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With