es5-shim & es5-sham

2016-12-24  本文已影响898人  从此以后dapeng

es5-shim

es5-shim.js and es5-shim.min.js monkey-patch a JavaScript context to
contain all EcmaScript 5 methods that can be faithfully emulated with a
legacy JavaScript engine.
Note: As es5-shim.js is designed to patch the native Javascript
engine, it should be the library that is loaded first.

es5-sham.js and es5-sham.min.js monkey-patch other ES5 methods as
closely as possible. For these methods, as closely as possible to ES5
is not very close. Many of these shams are intended only to allow code
to be written to ES5 without causing run-time errors in older engines.
In many cases, this means that these shams cause many ES5 methods to
silently fail. Decide carefully whether this is what you want.
Note: es5-sham.js requires es5-shim.js to be able to work properly.

Tests

The tests are written with the Jasmine BDD test framework.
To run the tests, navigate to <root-folder>/tests/ , or,
simply npm install and npm test.

Shims

Complete tests

Shams

May fail

Example of applying ES compatability shims in a browser project

<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-sham.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-sham.min.js"></script>
<script src="https://wzrd.in/standalone/es7-shim@latest"></script>
<script src="other-libs.js"></script>
上一篇 下一篇

猜你喜欢

热点阅读