Of course the example we just saw is not really practical, but it gives a good idea of what we want and it will help us appreciate the way the YUI library allows us to handle it. The onRadioButtonsClick()
function is a primitive event subscriber, and we could simply improve on that by using EventProvider. However, as soon as we wanted to add some extra functionality we would surely find that such a solution is very limited.
The reasonable solution is to define a class representing the set of radio buttons. Instead of creating the class from scratch, we will use YAHOO.util.Element
as its basis. All the most recent YUI controls inherit from Element, and so will we.
Element is a wrapper around a DOM node. It is what an idealized DOM object should be, consistent in its methods and properties. For those used to object-oriented programming it is the logical way to do it. Instead of having the DOM API, with all its quirks and issues and the YUI Dom and Events collection of utilities...