Prev | Current Page 740 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The event is determined by a string identifier passed as the second argument; to
know what events exist for every HTML element, refer to the events described in the HTML Appendix
and strip the on prefix. The third argument is the function that acts as a handler of the event; the function
accepts an Event object as an argument and returns nothing. The code shows a good technique to lessen
the differences between browsers; first of all no browser detection has been performed; instead a feature
detection technique has been adopted: If the method addEventListener() on the window object does
not exist, then the addEventListener() DOM method is not implemented at all and another solution
must be encountered. The second good practice is to perform the test just once and not every time the
function is accessed. To do that, on the first execution, the current method is replaced by one that is
adapted to the current browser and then immediately executed. Finally, note the necessity to wrap the
code in an untyped block to access low - level JavaScript features.


Pages:
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752