• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

es-shims/es5-shim: ECMAScript 5 compatibility shims for legacy (and modern) Java ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

es-shims/es5-shim

开源软件地址:

https://github.com/es-shims/es5-shim

开源编程语言:

JavaScript 98.0%

开源软件介绍:

es5-shim Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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 /tests/ , or, simply npm install and npm test.

Shims

Complete tests

Shams

  • ⚠️ Object.create

    For the case of simply "begetting" an object that inherits prototypically from another, this should work fine across legacy engines.

    ⚠️ The second argument is passed to Object.defineProperties which will probably fail either silently or with extreme prejudice.

  • ⚠️ Object.getPrototypeOf

    This will return "undefined" in some cases. It uses __proto__ if it's available. Failing that, it uses constructor.prototype, which depends on the constructor property of the object's prototype having not been replaced. If your object was created like this, it won't work:

      function Foo() {
      }
      Foo.prototype = {};
    

    Because the prototype reassignment destroys the constructor property.

    This will work for all objects that were created using Object.create implemented with this library.

  • ⚠️ Object.getOwnPropertyNames

    This method uses Object.keys, so it will not be accurate on legacy engines.

  • Object.isSealed

    Returns "false" in all legacy engines for all objects, which is conveniently guaranteed to be accurate.

  • Object.isFrozen

    Returns "false" in all legacy engines for all objects, which is conveniently guaranteed to be accurate.

  • Object.isExtensible

    Works like a charm, by trying very hard to extend the object then redacting the extension.

May fail

  • ⚠️ Object.getOwnPropertyDescriptor

    The behavior of this shim does not conform to ES5. It should probably not be used at this time, until its behavior has been reviewed and been confirmed to be useful in legacy engines.

  • ⚠️ Object.defineProperty

    In the worst of circumstances, IE 8 provides a version of this method that only works on DOM objects. This sham will not be installed. The given version of defineProperty will throw an exception if used on non-DOM objects.

    In slightly better circumstances, this method will silently fail to set "writable", "enumerable", and "configurable" properties.

    Providing a getter or setter with "get" or "set" on a descriptor will silently fail on engines that lack "defineGetter" and "defineSetter", which include all versions of IE.

    https://github.com/es-shims/es5-shim/issues#issue/5

  • ⚠️ Object.defineProperties

    This uses the Object.defineProperty shim.

  • Object.seal

    Silently fails on all legacy engines. This should be fine unless you are depending on the safety and security provisions of this method, which you cannot possibly obtain in legacy engines.

  • Object.freeze

    Silently fails on all legacy engines. This should be fine unless you are depending on the safety and security provisions of this method, which you cannot possibly obtain in legacy engines.

  • Object.preventExtensions

    Silently fails on all legacy engines. This should be fine unless you are depending on the safety and security provisions of this method, which you cannot possibly obtain in legacy engines.

Example of applying ES compatibility shims in a browser project

<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.14/es5-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.14/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.35.5/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-sham.min.js"></script>
<script src="other-libs.js"></script>



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
pypyjs/pypyjs: PyPy compiled to JavaScript发布时间:2022-07-07
下一篇:
pchen66/panolens.js: Javascript panorama viewer based on Three.js发布时间:2022-07-07
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap