13.4.1 Compatibility Libraries
excanvas.js is a particularly pure example of a compatibility library. It is possible to write similar libraries for certain features. The ES5 Array methods ( §7.9 ), such as forEach(), map(), and reduce(), can be almost perfectly emulated in ES3, and by adding the appropriate library to your pages, you can treat these powerfully useful methods as part of the baseline platform of all browsers.
Sometimes, however, it is not possible to completely (or efficiently) implement a feature on browsers that do not support it. As already mentioned, IE is the only browser that does not implement the standard event-handling API, including the addEventListener() method for registering event handlers. IE supports a similar method called attachEvent(). attachEvent() is not as powerful as addEventListener() and it is not really feasible to transparently implement the entire standard on top of what IE offers. Instead, developers sometimes define a compromise event handling method—often called addEvent()—that can be portably implemented using either addEventListener() or attachEvent(). Then, they write all their code to use addEvent() instead of either addEventListener() or attachEvent().欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/31414.html