JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

13.4.1 Compatibility Libraries

13.4.1 Compatibility Libraries


One of the easiest ways to deal with incompatibilities is to use libraries of code that work around them for you. Consider theelement for client-side graphics (the topic of Chapter 21 ), for example. IE is the only current browser that does not support this feature. It does support an obscure proprietary client-side graphics language called VML, however, and the canvas element can be emulated on top of that. The open source “explorercanvas” project at http://code.google.com/p/explorercanvas has released a library that does just that: you include a single file of JavaScript code named excanvas.js and IE will behave as if it supports theelement.

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
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1