Home

BareJS

The main purposes for BareJS are:

  • Provide an implementation for defining classes, interfaces and enums (decl)
  • Provide object lifetime management (Destroyable)
  • Provide a standard eventing mechanism (Evented)
  • Provide polyfills for standard JS functions and objects

What version should I use? BareJS has two output targets: node and browser.

  • node is for use in NodeJS. You should use bare.debug.js during development and bare.release.js to run production code.

  • browser is for use in browsers (and Rhino). During development you should use bare.debug.js, and on production you should select a suitable EcmaScript level release file. The name of the file reflects the assumed EcmaScript level of the target environments. For example, bare.es5.js will not include polyfills for methods like Array.prototype.forEach. If you target Rhino or any Internet Explorer version below 9, you should use bare.es3.js, which contains all polyfills.

    BareJS is built using WebPack, which outputs an Universal Module Definition. By default, BareJS will export a global barejs on which you can find BareJS's modules. If BareJS is loaded after an AMD loader has loaded, it will load as the AMD module "barejs". You can require "barejs" and access submodules via the container object, but you can also directly target submodules via AMD plugin syntax (in AMD loaders that support loader plugins). For example, decl can be loaded via "barejs!decl" and Map via "barejs!Map".

    For general use (targeting IE9+ and comparable browsers) it is best to use bare.es5.js. If only the most recent version of Chrome is targeted, it is safe to use bare.es6.js. (Note: these statements where written december 2015 and may no longer be true present day).

About Polyfills

BareJS includes polyfills of Objects and Functions that are part of the ECMA spec, but only if they can be polyfilled according to spec. Constructs like Object.defineProperty cannot be polyfilled since they depend features that need to be in the JavaScript engine. A few property/object related methods (like Object.defineProperty and Object.freeze) are also available on decl. These methods will try to do clever fallbacks in older environments, but you should be aware of these fallbacks whenever you want to execute in such environments. For example, Rhino and older ES3 browsers (except Internet Explorer) still support property getters and setters, only the configurable and enumerable flags are lost. If you prefer to use any other polyfill (e.g. es5-shim), be sure to use the bare.es5.js version to avoid loading duplicate polyfills.

Note that BareJS does not export polyfills for newer objects like Map, WeakMap or Promise in the global scope. It does add standards compliant functions to global objects like Array, Function and Object, with enumerability/configurability flags. If you target browsers that do not support the enumerability flags, you should avoid enumerating Arrays with for..in or be sure to include hasOwnProperty checks. BareJS will always prefer existing globals over its own polyfills, so if you have any custom Promise, Map, WeakMap or other polyfill, be sure to load it before loading BareJS.