In particular, Dojo provides a built in implementation of the dispatcher object unrelated document through the methods and manageable .subscribe() and .publish(). This system, called Topics in is based on the creation of channels through which they will broadcast the event on which the related functions are in play:
Code:
// Add a function to listen on channel 'mychannel'
dojo.subscribe ('mychannel', function (message) {
alert ('New Message:' + message);
});
// Will display a dialog box 'New Message: It works!'
dojo.publish ('mychannel', ['works !']);
The advantage of this system is to be completely detached from the DOM and not be tied to its context with regard to the property this, which can create problems in other implementations:
Code:
$ (Document). Bind ('mioEvento', function () {
// This document is
});
$ ('# MioForm'). Bind ('submit', function () {
/ / This is only in this context # mioForm
/ / In the context. Trigger () becomes a document
$ (Document). Trigger ('changer');
});
Despite the environment are often little consideration of web developers, JavaScript has become increasingly important in recent years, see that increasing the size and complexity of applications based on it. Designing and coding scalable through the use of custom events is becoming a key requirement to ensure reliability and longevity of our projects.
Bookmarks