es6-shim-0.35.6.zip
立即下载
资源介绍:
es6-shim-0.35.6.zip
# ES6 Shim
Provides compatibility shims so that legacy JavaScript engines behave as
closely as possible to ECMAScript 6 (Harmony).
[![Build Status][1]][2] [![dependency status][3]][4] [![dev dependency status][5]][6]
[![browser support](https://ci.testling.com/paulmillr/es6-shim.png)](https://ci.testling.com/paulmillr/es6-shim)
[![Sauce Test Status](https://saucelabs.com/browser-matrix/es6-shim.svg)](https://saucelabs.com/u/es6-shim)
[HTML version of the final ECMAScript 6 spec][spec-html-url]
## Installation
If you want to use it in browser:
* Just include `es6-shim` before your scripts.
* Include [es5-shim][es5-shim-url] especially if your browser doesn't support ECMAScript 5 - but every JS engine requires the `es5-shim` to correct broken implementations, so it's strongly recommended to always include it. Additionally, `es5-shim` should be loaded before `es6-shim`.
For `node.js`, `io.js`, or any `npm`-managed workflow (this is the recommended method):
npm install es6-shim
Alternative methods:
* `component install paulmillr/es6-shim` if you’re using [component(1)](https://github.com/componentjs/component).
* `bower install es6-shim` if you’re using [Bower](http://bower.io/).
In both browser and node you may also want to include `unorm`; see the [`String.prototype.normalize`](#stringprototypenormalize) section for details.
## Safe shims
* `Map`, `Set` (requires ES5 property descriptor support)
* `Promise`
* `String`:
* `fromCodePoint()` ([a standalone shim is also available](https://npmjs.com/string.fromcodepoint))
* `raw()`
* `String.prototype`:
* `codePointAt()` ([a standalone shim is also available](https://npmjs.com/string.prototype.codepointat))
* `endsWith()` ([a standalone shim is also available](https://npmjs.com/string.prototype.endswith))
* `includes()` ([a standalone shim is also available](https://npmjs.com/string.prototype.includes))
* `repeat()` ([a standalone shim is also available](https://npmjs.com/string.prototype.repeat))
* `startsWith()` ([a standalone shim is also available](https://npmjs.com/string.prototype.startswith))
* `RegExp`:
* `new RegExp`, when given a RegExp as the pattern, will no longer throw when given a "flags" string argument. (requires ES5)
* `RegExp.prototype`:
* `flags` (requires ES5) ([a standalone shim is also available](https://npmjs.com/regexp.prototype.flags))
* `[Symbol.match]` (requires native `Symbol`s)
* `[Symbol.replace]` (requires native `Symbol`s)
* `[Symbol.search]` (requires native `Symbol`s)
* `[Symbol.split]` (requires native `Symbol`s)
* `toString`
* `Number`:
* binary and octal literals: `Number('0b1')` and `Number('0o7')`
* `EPSILON`
* `MAX_SAFE_INTEGER`
* `MIN_SAFE_INTEGER`
* `isNaN()`([a standalone shim is also available](https://www.npmjs.com/package/is-nan))
* `isInteger()`
* `isSafeInteger()`
* `isFinite()`
* `parseInt()`
* `parseFloat()`
* `Array`:
* `from()` ([a standalone shim is also available](https://www.npmjs.com/package/array.from))
* `of()` ([a standalone shim is also available](https://www.npmjs.com/package/array.of))
* `Array.prototype`:
* `copyWithin()`
* `entries()` ([a standalone shim is also available](https://npmjs.com/array.prototype.entries))
* `fill()`
* `find()` ([a standalone shim is also available](https://npmjs.com/array.prototype.find))
* `findIndex()` ([a standalone shim is also available](https://npmjs.com/array.prototype.findindex))
* `keys()` ([a standalone shim is also available](https://npmjs.com/array.prototype.keys))
* `values()` ([a standalone shim is also available](https://npmjs.com/array.prototype.values))
* `indexOf()` (ES6 errata) ([a standalone shim is also available](https://npmjs.com/array.prototype.indexof))
* `Object`:
* `assign()` ([a standalone shim is also available](https://npmjs.com/object.assign))
* `is()` ([a standalone shim is also available](https://npmjs.com/object-is))
* `keys()` (in ES5, but no longer throws on non-object non-null/undefined values in ES6) ([a standalone shim is also available](https://npmjs.com/object-keys)
* `setPrototypeOf()` (IE >= 11)
* `Function.prototype`:
* `name` (es6-sham, covers IE 9-11) ([a standalone shim is also available](https://npmjs.com/function.prototype.name)
* `Math`:
* `acosh()`
* `asinh()`
* `atanh()`
* `cbrt()`
* `clz32()`
* `cosh()`
* `expm1()`
* `fround()`
* `hypot()`
* `imul()`
* `log10()`
* `log1p()`
* `log2()`
* `sign()`
* `sinh()`
* `tanh()`
* `trunc()`
Math functions’ accuracy is 1e-11.
* `Reflect`
* `apply()`
* `construct()`
* `defineProperty()`
* `deleteProperty()`
* `get()`
* `getOwnPropertyDescriptor()`
* `getPrototypeOf()`
* `has()`
* `isExtensible()`
* `ownKeys()` ([a standalone shim is also available](https://npmjs.com/reflect.ownkeys))
* `preventExtensions()`
* `set()`
* `setPrototypeOf()`
* `Symbol` (only if it already exists)
* `match` (and corresponding `String#match`, `String#startsWith`, `String#endsWith`, `String#includes`, `RegExp` support)
* `replace` (and corresponding `String#replace` support)
* `search` (and corresponding `String#search` support)
* `split` (and corresponding `String#split` support)
Well-known symbols will only be provided if the engine already has `Symbol` support.
* `String.prototype` Annex B HTML methods
* `anchor()`
* `big()`
* `blink()`
* `bold()`
* `fixed()`
* `fontcolor()`
* `fontsize()`
* `italics()`
* `link()`
* `small()`
* `strike()`
* `sub()`
* `sup()`
These methods are part of "Annex B", which means that although they are a defacto standard, you shouldn't use them. None the less, the `es6-shim` provides them and normalizes their behavior across browsers.
## Subclassing
The `Map`, `Set`, and `Promise` implementations are subclassable.
You should use the following pattern to create a subclass in ES5 which will continue to work in ES6:
```javascript
require('es6-shim');
function MyPromise(exec) {
var promise = new Promise(exec);
Object.setPrototypeOf(promise, MyPromise.prototype);
// ...
return promise;
}
Object.setPrototypeOf(MyPromise, Promise);
MyPromise.prototype = Object.create(Promise.prototype, {
constructor: { value: MyPromise }
});
```
## String.prototype.normalize
Including a proper shim for `String.prototype.normalize` would increase the size of this library by a factor of more than 4.
So instead we recommend that you install the [`unorm`](https://github.com/walling/unorm) package alongside `es6-shim` if you need `String.prototype.normalize`.
See https://github.com/paulmillr/es6-shim/issues/134 for more discussion.
## WeakMap shim
It is not possible to implement WeakMap in pure javascript.
The [es6-collections](https://github.com/WebReflection/es6-collections) implementation doesn't hold values strongly, which is critical for the collection. `es6-shim` decided to not include an incorrect shim.
`WeakMap` has very unusual use-cases, so you probably won't need it at all (use simple `Map` instead).
## Getting started
```javascript
require('es6-shim');
var assert = require('assert');
assert.equal(true, 'abc'.startsWith('a'));
assert.equal(false, 'abc'.endsWith('a'));
assert.equal(true, 'john alice'.includes('john'));
assert.equal('123'.repeat(2), '123123');
assert.equal(false, NaN === NaN);
assert.equal(true, Object.is(NaN, NaN));
assert.equal(true, -0 === 0);
assert.equal(false, Object.is(-0, 0));
var result = Object.assign({ a: 1 }, { b: 2 });
assert.deepEqual(result, { a: 1, b: 2 });
assert.equal(true, isNaN('a'));
assert.equal(false, Number.isNaN('a'));
assert.equal(true, Number.isNaN(NaN));
assert.equal(true, isFinite('123'));
assert.equal(false, Number.isFinite('123'));
assert.equal(false, Number.isFinite(Infinity));
// Tests if value is a num