Coder Social home page Coder Social logo

es5-shim's Introduction

Provides compatibility shims so that legacy JavaScript
engines behave as closely as possible to ES5.

This package requires quite a bit more attention and
testing.  It is not likely to behave as advertised in a
large cross-section of browsers.

"As closely as possible to ES5" is not very close.  Many of
these shims 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 shims cause many ES5
methods to silently fail.  Decide carefully whether this is
what you want.


SAFE SHIMS
----------

Array.isArray
Array.prototype.forEach
Array.prototype.map
Array.prototype.filter
Array.prototype.every
Array.prototype.some
Array.prototype.reduce
Array.prototype.reduceRight
Array.prototype.indexOf
Array.prototype.lastIndexOf
Object.keys
Date.now
Date.parse (for ISO parsing)
Date.prototype.toISOString
Date.prototype.toJSON
Function.prototype.bind
String.prototype.trim


DUBIOUS SHIMS
-------------

/?\ Object.create

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

    /!\ Object.create(null) will work only in browsers that
    support prototype assignment.  This creates an object
    that does not have any properties inherited from
    Object.prototype.  It will silently fail otherwise.

    /!\ The second argument is passed to
    Object.defineProperties which will probably fail
    silently.

/?\ 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.


SHIMS THAT FAIL SILENTLY
------------------------

/!\ 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

    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 up to version 8 so far.

    IE 8 provides a version of this method but it only works
    on DOM objects.  Thus, the shim will not get installed
    and attempts to set "value" properties will fail
    silently on non-DOM objects.

    https://github.com/kriskowal/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 safty 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 safty 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 safty and security
    provisions of this method, which you cannot possibly
    obtain in legacy engines.

/!\ Object.isExtensible

    Returns "true". This is probably wildly innacurate.
    This method should be reviewed before it's used.

es5-shim's People

Contributors

domenic avatar fschaefer avatar gozala avatar hax avatar kriskowal avatar raynos avatar samsonjs avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.