TAILIEUCHUNG - Test Driven JavaScript Development- P12

Test Driven JavaScript Development- P12:This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage, and gaining the ability to fearlessly refactor and organically evolve your code base. It is about writing modular and testable code. It is about writing JavaScript that works in a wide variety of environments and that doesn’t get in your user’s way. | Using Feature Detection 213 return event element listener return _addEventHandler element event listener addEventHandler The mouseenter implementation keeps track of whether the mouse is currently hovering the target element and fires anytime a mouseover is fired and the mouse wasn t previously hovering it. The method uses parent child which returns true if an element contains another. The try-catch protects against a bug in Firefox which will sometimes provide an XUL element as relatedTarget. This can happen when mousing over for instance a scroll bar and unfortunately XUL elements throw exceptions on any property access. Additionally the relatedTarget may be a text node fetching its parentNode gets us back on track. To practice feature detection I encourage you to take this method for a spin find more browser quirks and smooth them over by detecting erroneous behavior and correcting it. Using Feature Detection Feature detection is a powerful tool in cross-browser scripting. It can allow many features to be implemented for a very wide array of browsers old current and future ones. That does not necessarily mean that employing feature detection implies that you should provide fallback solutions for any feature that may not be supported. Sometimes dropping support for old browsers can be a statement in itself but we should be able to do so without sniffing out the browsers we want to send down the degradation path. Moving Forward If supporting a troublesome old browser oh say Internet Explorer 6 costs more than the benefits can defend businesses sometimes actively decide to drop support. Doing so does not mean we should pretend unsupported browsers don t exist. Using unobtrusive JavaScript and feature detection can ensure that when a browser is no longer actively developed for it will receive the usable but possibly Please purchase PDF Split-Merge on to remove this watermark. From the