UNPKG

100 kBMarkdownView Raw
1# core-js
2
3[![Sponsors on Open Collective](https://opencollective.com/core-js/sponsors/badge.svg)](#raising-funds) [![Backers on Open Collective](https://opencollective.com/core-js/backers/badge.svg)](#raising-funds) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/zloirock/core-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![version](https://img.shields.io/npm/v/core-js.svg)](https://www.npmjs.com/package/core-js) [![npm downloads](https://img.shields.io/npm/dm/core-js.svg)](http://npm-stat.com/charts.html?package=core-js&author=&from=2014-11-18) [![Build Status](https://travis-ci.org/zloirock/core-js.svg)](https://travis-ci.org/zloirock/core-js) [![devDependency status](https://david-dm.org/zloirock/core-js/dev-status.svg)](https://david-dm.org/zloirock/core-js?type=dev)
4## As advertising: the author is looking for a good job :)
5
6## [core-js@3, babel and a look into the future](https://github.com/zloirock/core-js/tree/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md)
7
8## Raising funds
9
10`core-js` isn't backed by a company, so the future of this project depends on you. Become a sponsor or a backer [**on Open Collective**](https://opencollective.com/core-js) or [**on Patreon**](https://www.patreon.com/zloirock) if you are interested in `core-js`.
11
12---
13
14<a href="https://opencollective.com/core-js/sponsor/0/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/0/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/1/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/1/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/2/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/2/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/3/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/3/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/4/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/4/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/5/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/5/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/6/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/6/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/7/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/7/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/8/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/8/avatar.svg"></a><a href="https://opencollective.com/core-js/sponsor/9/website" target="_blank"><img src="https://opencollective.com/core-js/sponsor/9/avatar.svg"></a>
15
16---
17
18<a href="https://opencollective.com/core-js#backers" target="_blank"><img src="https://opencollective.com/core-js/backers.svg?width=890"></a>
19
20---
21
22**It's documentation for obsolete `core-js@2`. If you looking documentation for actual `core-js` version, please, check [this branch](https://github.com/zloirock/core-js/tree/master).**
23
24Modular standard library for JavaScript. Includes polyfills for [ECMAScript 5](#ecmascript-5), [ECMAScript 6](#ecmascript-6): [promises](#ecmascript-6-promise), [symbols](#ecmascript-6-symbol), [collections](#ecmascript-6-collections), iterators, [typed arrays](#ecmascript-6-typed-arrays), [ECMAScript 7+ proposals](#ecmascript-7-proposals), [setImmediate](#setimmediate), etc. Some additional features such as [dictionaries](#dict) or [extended partial application](#partial-application). You can require only needed features or use it without global namespace pollution.
25
26[*Example*](http://goo.gl/a2xexl):
27```js
28Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
29'*'.repeat(10); // => '**********'
30Promise.resolve(32).then(x => console.log(x)); // => 32
31setImmediate(x => console.log(x), 42); // => 42
32```
33
34[*Without global namespace pollution*](http://goo.gl/paOHb0):
35```js
36var core = require('core-js/library'); // With a modular system, otherwise use global `core`
37core.Array.from(new core.Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
38core.String.repeat('*', 10); // => '**********'
39core.Promise.resolve(32).then(x => console.log(x)); // => 32
40core.setImmediate(x => console.log(x), 42); // => 42
41```
42
43### Index
44- [Usage](#usage)
45 - [Basic](#basic)
46 - [CommonJS](#commonjs)
47 - [Custom build](#custom-build-from-the-command-line)
48- [Supported engines](#supported-engines)
49- [Features](#features)
50 - [ECMAScript 5](#ecmascript-5)
51 - [ECMAScript 6](#ecmascript-6)
52 - [ECMAScript 6: Object](#ecmascript-6-object)
53 - [ECMAScript 6: Function](#ecmascript-6-function)
54 - [ECMAScript 6: Array](#ecmascript-6-array)
55 - [ECMAScript 6: String](#ecmascript-6-string)
56 - [ECMAScript 6: RegExp](#ecmascript-6-regexp)
57 - [ECMAScript 6: Number](#ecmascript-6-number)
58 - [ECMAScript 6: Math](#ecmascript-6-math)
59 - [ECMAScript 6: Date](#ecmascript-6-date)
60 - [ECMAScript 6: Promise](#ecmascript-6-promise)
61 - [ECMAScript 6: Symbol](#ecmascript-6-symbol)
62 - [ECMAScript 6: Collections](#ecmascript-6-collections)
63 - [ECMAScript 6: Typed Arrays](#ecmascript-6-typed-arrays)
64 - [ECMAScript 6: Reflect](#ecmascript-6-reflect)
65 - [ECMAScript 7+ proposals](#ecmascript-7-proposals)
66 - [stage 4 proposals](#stage-4-proposals)
67 - [stage 3 proposals](#stage-3-proposals)
68 - [stage 2 proposals](#stage-2-proposals)
69 - [stage 1 proposals](#stage-1-proposals)
70 - [stage 0 proposals](#stage-0-proposals)
71 - [pre-stage 0 proposals](#pre-stage-0-proposals)
72 - [Web standards](#web-standards)
73 - [setTimeout / setInterval](#settimeout--setinterval)
74 - [setImmediate](#setimmediate)
75 - [iterable DOM collections](#iterable-dom-collections)
76 - [Non-standard](#non-standard)
77 - [Object](#object)
78 - [Dict](#dict)
79 - [partial application](#partial-application)
80 - [Number Iterator](#number-iterator)
81 - [escaping strings](#escaping-strings)
82 - [delay](#delay)
83 - [helpers for iterators](#helpers-for-iterators)
84- [Missing polyfills](#missing-polyfills)
85- [Changelog](./CHANGELOG.md)
86
87## Usage
88### Basic
89```
90npm i core-js
91bower install core.js
92```
93
94```js
95// Default
96require('core-js');
97// Without global namespace pollution
98var core = require('core-js/library');
99// Shim only
100require('core-js/shim');
101```
102If you need complete build for browser, use builds from `core-js/client` path:
103
104* [default](https://raw.githack.com/zloirock/core-js/v2.6.10/client/core.min.js): Includes all features, standard and non-standard.
105* [as a library](https://raw.githack.com/zloirock/core-js/v2.6.10/client/library.min.js): Like "default", but does not pollute the global namespace (see [2nd example at the top](#core-js)).
106* [shim only](https://raw.githack.com/zloirock/core-js/v2.6.10/client/shim.min.js): Only includes the standard methods.
107
108Warning: if you use `core-js` with the extension of native objects, require all needed `core-js` modules at the beginning of entry point of your application, otherwise, conflicts may occur.
109
110### CommonJS
111You can require only needed modules.
112
113```js
114require('core-js/fn/set');
115require('core-js/fn/array/from');
116require('core-js/fn/array/find-index');
117Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
118[1, 2, NaN, 3, 4].findIndex(isNaN); // => 2
119
120// or, w/o global namespace pollution:
121
122var Set = require('core-js/library/fn/set');
123var from = require('core-js/library/fn/array/from');
124var findIndex = require('core-js/library/fn/array/find-index');
125from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
126findIndex([1, 2, NaN, 3, 4], isNaN); // => 2
127```
128Available entry points for methods / constructors, as above examples, and namespaces: for example, `core-js/es6/array` (`core-js/library/es6/array`) contains all [ES6 `Array` features](#ecmascript-6-array), `core-js/es6` (`core-js/library/es6`) contains all ES6 features.
129
130##### Caveats when using CommonJS API:
131
132* `modules` path is internal API, does not inject all required dependencies and can be changed in minor or patch releases. Use it only for a custom build and / or if you know what are you doing.
133* `core-js` is extremely modular and uses a lot of very tiny modules, because of that for usage in browsers bundle up `core-js` instead of usage loader for each file, otherwise, you will have hundreds of requests.
134
135#### CommonJS and prototype methods without global namespace pollution
136In the `library` version, we can't pollute prototypes of native constructors. Because of that, prototype methods transformed to static methods like in examples above. `babel` `runtime` transformer also can't transform them. But with transpilers we can use one more trick - [bind operator and virtual methods](https://github.com/zenparsing/es-function-bind). Special for that, available `/virtual/` entry points. Example:
137```js
138import fill from 'core-js/library/fn/array/virtual/fill';
139import findIndex from 'core-js/library/fn/array/virtual/find-index';
140
141Array(10)::fill(0).map((a, b) => b * b)::findIndex(it => it && !(it % 8)); // => 4
142
143// or
144
145import {fill, findIndex} from 'core-js/library/fn/array/virtual';
146
147Array(10)::fill(0).map((a, b) => b * b)::findIndex(it => it && !(it % 8)); // => 4
148
149```
150
151### Custom build (from the command-line)
152```
153npm i core-js && cd node_modules/core-js && npm i
154npm run grunt build:core.dict,es6 -- --blacklist=es6.promise,es6.math --library=on --path=custom uglify
155```
156Where `core.dict` and `es6` are modules (namespaces) names, which will be added to the build, `es6.promise` and `es6.math` are modules (namespaces) names, which will be excluded from the build, `--library=on` is flag for build without global namespace pollution and `custom` is target file name.
157
158Available namespaces: for example, `es6.array` contains [ES6 `Array` features](#ecmascript-6-array), `es6` contains all modules whose names start with `es6`.
159
160### Custom build (from external scripts)
161
162[`core-js-builder`](https://www.npmjs.com/package/core-js-builder) package exports a function that takes the same parameters as the `build` target from the previous section. This will conditionally include or exclude certain parts of `core-js`:
163
164```js
165require('core-js-builder')({
166 modules: ['es6', 'core.dict'], // modules / namespaces
167 blacklist: ['es6.reflect'], // blacklist of modules / namespaces, by default - empty list
168 library: false, // flag for build without global namespace pollution, by default - false
169 umd: true // use UMD wrapper for export `core` object, by default - true
170}).then(code => {
171 // ...
172}).catch(error => {
173 // ...
174});
175```
176## Supported engines
177**Tested in:**
178- Chrome 26+
179- Firefox 4+
180- Safari 5+
181- Opera 12+
182- Internet Explorer 6+ (sure, IE8- with ES3 limitations)
183- Edge
184- Android Browser 2.3+
185- iOS Safari 5.1+
186- PhantomJS 1.9 / 2.1
187- NodeJS 0.8+
188
189...and it doesn't mean `core-js` will not work in other engines, they just have not been tested.
190
191## Features:
192[*CommonJS entry points:*](#commonjs)
193```
194core-js(/library) <- all features
195core-js(/library)/shim <- only polyfills
196```
197### ECMAScript 5
198All features moved to the [`es6` namespace](#ecmascript-6), here just a list of features:
199```js
200Object
201 .create(proto | null, descriptors?) -> object
202 .getPrototypeOf(object) -> proto | null
203 .defineProperty(target, key, desc) -> target, cap for ie8-
204 .defineProperties(target, descriptors) -> target, cap for ie8-
205 .getOwnPropertyDescriptor(object, key) -> desc
206 .getOwnPropertyNames(object) -> array
207 .keys(object) -> array
208 .seal(object) -> object, cap for ie8-
209 .freeze(object) -> object, cap for ie8-
210 .preventExtensions(object) -> object, cap for ie8-
211 .isSealed(object) -> bool, cap for ie8-
212 .isFrozen(object) -> bool, cap for ie8-
213 .isExtensible(object) -> bool, cap for ie8-
214Array
215 .isArray(var) -> bool
216 #slice(start?, end?) -> array, fix for ie7-
217 #join(string = ',') -> string, fix for ie7-
218 #indexOf(var, from?) -> int
219 #lastIndexOf(var, from?) -> int
220 #every(fn(val, index, @), that) -> bool
221 #some(fn(val, index, @), that) -> bool
222 #forEach(fn(val, index, @), that) -> void
223 #map(fn(val, index, @), that) -> array
224 #filter(fn(val, index, @), that) -> array
225 #reduce(fn(memo, val, index, @), memo?) -> var
226 #reduceRight(fn(memo, val, index, @), memo?) -> var
227 #sort(fn?) -> @, fixes for some engines
228Function
229 #bind(object, ...args) -> boundFn(...args)
230String
231 #split(separator, limit) -> array
232 #trim() -> str
233RegExp
234 #toString() -> str
235Number
236 #toFixed(digits) -> string
237 #toPrecision(precision) -> string
238parseInt(str, radix) -> int
239parseFloat(str) -> num
240Date
241 .now() -> int
242 #toISOString() -> string
243 #toJSON() -> string
244```
245[*CommonJS entry points:*](#commonjs)
246```
247core-js(/library)/es5
248```
249
250### ECMAScript 6
251[*CommonJS entry points:*](#commonjs)
252```
253core-js(/library)/es6
254```
255#### ECMAScript 6: Object
256Modules [`es6.object.assign`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.assign.js), [`es6.object.is`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.is.js), [`es6.object.set-prototype-of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.set-prototype-of.js) and [`es6.object.to-string`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.to-string.js).
257
258In ES6 most `Object` static methods should work with primitives. Modules [`es6.object.freeze`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.freeze.js), [`es6.object.seal`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.seal.js), [`es6.object.prevent-extensions`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.prevent-extensions.js), [`es6.object.is-frozen`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.is-frozen.js), [`es6.object.is-sealed`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.is-sealed.js), [`es6.object.is-extensible`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.is-extensible.js), [`es6.object.get-own-property-descriptor`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.get-own-property-descriptor.js), [`es6.object.get-prototype-of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.get-prototype-of.js), [`es6.object.keys`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.keys.js) and [`es6.object.get-own-property-names`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.get-own-property-names.js).
259
260Just ES5 features: [`es6.object.create`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.create.js), [`es6.object.define-property`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.define-property.js) and [`es6.object.define-properties`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.object.es6.object.define-properties.js).
261```js
262Object
263 .assign(target, ...src) -> target
264 .is(a, b) -> bool
265 .setPrototypeOf(target, proto | null) -> target (required __proto__ - IE11+)
266 .create(object | null, descriptors?) -> object
267 .getPrototypeOf(var) -> object | null
268 .defineProperty(object, key, desc) -> target
269 .defineProperties(object, descriptors) -> target
270 .getOwnPropertyDescriptor(var, key) -> desc | undefined
271 .keys(var) -> array
272 .getOwnPropertyNames(var) -> array
273 .freeze(var) -> var
274 .seal(var) -> var
275 .preventExtensions(var) -> var
276 .isFrozen(var) -> bool
277 .isSealed(var) -> bool
278 .isExtensible(var) -> bool
279 #toString() -> string, ES6 fix: @@toStringTag support
280```
281[*CommonJS entry points:*](#commonjs)
282```
283core-js(/library)/es6/object
284core-js(/library)/fn/object/assign
285core-js(/library)/fn/object/is
286core-js(/library)/fn/object/set-prototype-of
287core-js(/library)/fn/object/get-prototype-of
288core-js(/library)/fn/object/create
289core-js(/library)/fn/object/define-property
290core-js(/library)/fn/object/define-properties
291core-js(/library)/fn/object/get-own-property-descriptor
292core-js(/library)/fn/object/keys
293core-js(/library)/fn/object/get-own-property-names
294core-js(/library)/fn/object/freeze
295core-js(/library)/fn/object/seal
296core-js(/library)/fn/object/prevent-extensions
297core-js(/library)/fn/object/is-frozen
298core-js(/library)/fn/object/is-sealed
299core-js(/library)/fn/object/is-extensible
300core-js/fn/object/to-string
301```
302[*Examples*](http://goo.gl/ywdwPz):
303```js
304var foo = {q: 1, w: 2}
305 , bar = {e: 3, r: 4}
306 , baz = {t: 5, y: 6};
307Object.assign(foo, bar, baz); // => foo = {q: 1, w: 2, e: 3, r: 4, t: 5, y: 6}
308
309Object.is(NaN, NaN); // => true
310Object.is(0, -0); // => false
311Object.is(42, 42); // => true
312Object.is(42, '42'); // => false
313
314function Parent(){}
315function Child(){}
316Object.setPrototypeOf(Child.prototype, Parent.prototype);
317new Child instanceof Child; // => true
318new Child instanceof Parent; // => true
319
320var O = {};
321O[Symbol.toStringTag] = 'Foo';
322'' + O; // => '[object Foo]'
323
324Object.keys('qwe'); // => ['0', '1', '2']
325Object.getPrototypeOf('qwe') === String.prototype; // => true
326```
327#### ECMAScript 6: Function
328Modules [`es6.function.name`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.function.name.js), [`es6.function.has-instance`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.function.has-instance.js). Just ES5: [`es6.function.bind`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.function.bind.js).
329```js
330Function
331 #bind(object, ...args) -> boundFn(...args)
332 #name -> string (IE9+)
333 #@@hasInstance(var) -> bool
334```
335[*CommonJS entry points:*](#commonjs)
336```
337core-js/es6/function
338core-js/fn/function/name
339core-js/fn/function/has-instance
340core-js/fn/function/bind
341core-js/fn/function/virtual/bind
342```
343[*Example*](http://goo.gl/zqu3Wp):
344```js
345(function foo(){}).name // => 'foo'
346
347console.log.bind(console, 42)(43); // => 42 43
348```
349#### ECMAScript 6: Array
350Modules [`es6.array.from`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.from.js), [`es6.array.of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.of.js), [`es6.array.copy-within`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.copy-within.js), [`es6.array.fill`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.fill.js), [`es6.array.find`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.find.js), [`es6.array.find-index`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.find-index.js), [`es6.array.iterator`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.iterator.js). ES5 features with fixes: [`es6.array.is-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.is-array.js), [`es6.array.slice`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.slice.js), [`es6.array.join`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.join.js), [`es6.array.index-of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.index-of.js), [`es6.array.last-index-of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.last-index-of.js), [`es6.array.every`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.every.js), [`es6.array.some`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.some.js), [`es6.array.for-each`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.for-each.js), [`es6.array.map`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.map.js), [`es6.array.filter`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.filter.js), [`es6.array.reduce`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.reduce.js), [`es6.array.reduce-right`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.reduce-right.js), [`es6.array.sort`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.array.sort.js).
351```js
352Array
353 .from(iterable | array-like, mapFn(val, index)?, that) -> array
354 .of(...args) -> array
355 .isArray(var) -> bool
356 #copyWithin(target = 0, start = 0, end = @length) -> @
357 #fill(val, start = 0, end = @length) -> @
358 #find(fn(val, index, @), that) -> val
359 #findIndex(fn(val, index, @), that) -> index | -1
360 #values() -> iterator
361 #keys() -> iterator
362 #entries() -> iterator
363 #join(string = ',') -> string, fix for ie7-
364 #slice(start?, end?) -> array, fix for ie7-
365 #indexOf(var, from?) -> index | -1
366 #lastIndexOf(var, from?) -> index | -1
367 #every(fn(val, index, @), that) -> bool
368 #some(fn(val, index, @), that) -> bool
369 #forEach(fn(val, index, @), that) -> void
370 #map(fn(val, index, @), that) -> array
371 #filter(fn(val, index, @), that) -> array
372 #reduce(fn(memo, val, index, @), memo?) -> var
373 #reduceRight(fn(memo, val, index, @), memo?) -> var
374 #sort(fn?) -> @, invalid arguments fix
375 #@@iterator() -> iterator (values)
376 #@@unscopables -> object (cap)
377Arguments
378 #@@iterator() -> iterator (values, available only in core-js methods)
379```
380[*CommonJS entry points:*](#commonjs)
381```
382core-js(/library)/es6/array
383core-js(/library)/fn/array/from
384core-js(/library)/fn/array/of
385core-js(/library)/fn/array/is-array
386core-js(/library)/fn/array/iterator
387core-js(/library)/fn/array/copy-within
388core-js(/library)/fn/array/fill
389core-js(/library)/fn/array/find
390core-js(/library)/fn/array/find-index
391core-js(/library)/fn/array/values
392core-js(/library)/fn/array/keys
393core-js(/library)/fn/array/entries
394core-js(/library)/fn/array/slice
395core-js(/library)/fn/array/join
396core-js(/library)/fn/array/index-of
397core-js(/library)/fn/array/last-index-of
398core-js(/library)/fn/array/every
399core-js(/library)/fn/array/some
400core-js(/library)/fn/array/for-each
401core-js(/library)/fn/array/map
402core-js(/library)/fn/array/filter
403core-js(/library)/fn/array/reduce
404core-js(/library)/fn/array/reduce-right
405core-js(/library)/fn/array/sort
406core-js(/library)/fn/array/virtual/iterator
407core-js(/library)/fn/array/virtual/copy-within
408core-js(/library)/fn/array/virtual/fill
409core-js(/library)/fn/array/virtual/find
410core-js(/library)/fn/array/virtual/find-index
411core-js(/library)/fn/array/virtual/values
412core-js(/library)/fn/array/virtual/keys
413core-js(/library)/fn/array/virtual/entries
414core-js(/library)/fn/array/virtual/slice
415core-js(/library)/fn/array/virtual/join
416core-js(/library)/fn/array/virtual/index-of
417core-js(/library)/fn/array/virtual/last-index-of
418core-js(/library)/fn/array/virtual/every
419core-js(/library)/fn/array/virtual/some
420core-js(/library)/fn/array/virtual/for-each
421core-js(/library)/fn/array/virtual/map
422core-js(/library)/fn/array/virtual/filter
423core-js(/library)/fn/array/virtual/reduce
424core-js(/library)/fn/array/virtual/reduce-right
425core-js(/library)/fn/array/virtual/sort
426```
427[*Examples*](http://goo.gl/oaUFUf):
428```js
429Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
430Array.from({0: 1, 1: 2, 2: 3, length: 3}); // => [1, 2, 3]
431Array.from('123', Number); // => [1, 2, 3]
432Array.from('123', function(it){
433 return it * it;
434}); // => [1, 4, 9]
435
436Array.of(1); // => [1]
437Array.of(1, 2, 3); // => [1, 2, 3]
438
439var array = ['a', 'b', 'c'];
440
441for(var val of array)console.log(val); // => 'a', 'b', 'c'
442for(var val of array.values())console.log(val); // => 'a', 'b', 'c'
443for(var key of array.keys())console.log(key); // => 0, 1, 2
444for(var [key, val] of array.entries()){
445 console.log(key); // => 0, 1, 2
446 console.log(val); // => 'a', 'b', 'c'
447}
448
449function isOdd(val){
450 return val % 2;
451}
452[4, 8, 15, 16, 23, 42].find(isOdd); // => 15
453[4, 8, 15, 16, 23, 42].findIndex(isOdd); // => 2
454[4, 8, 15, 16, 23, 42].find(isNaN); // => undefined
455[4, 8, 15, 16, 23, 42].findIndex(isNaN); // => -1
456
457Array(5).fill(42); // => [42, 42, 42, 42, 42]
458
459[1, 2, 3, 4, 5].copyWithin(0, 3); // => [4, 5, 3, 4, 5]
460```
461#### ECMAScript 6: String
462Modules [`es6.string.from-code-point`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.from-code-point.js), [`es6.string.raw`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.raw.js), [`es6.string.iterator`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.iterator.js), [`es6.string.code-point-at`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.code-point-at.js), [`es6.string.ends-with`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.ends-with.js), [`es6.string.includes`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.includes.js), [`es6.string.repeat`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.repeat.js), [`es6.string.starts-with`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.starts-with.js) and [`es6.string.trim`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.trim.js).
463
464Annex B HTML methods. Ugly, but it's also the part of the spec. Modules [`es6.string.anchor`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.anchor.js), [`es6.string.big`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.big.js), [`es6.string.blink`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.blink.js), [`es6.string.bold`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.bold.js), [`es6.string.fixed`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.fixed.js), [`es6.string.fontcolor`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.fontcolor.js), [`es6.string.fontsize`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.fontsize.js), [`es6.string.italics`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.italics.js), [`es6.string.link`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.link.js), [`es6.string.small`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.small.js), [`es6.string.strike`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.strike.js), [`es6.string.sub`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.sub.js) and [`es6.string.sup`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.string.sup.js).
465```js
466String
467 .fromCodePoint(...codePoints) -> str
468 .raw({raw}, ...substitutions) -> str
469 #includes(str, from?) -> bool
470 #startsWith(str, from?) -> bool
471 #endsWith(str, from?) -> bool
472 #repeat(num) -> str
473 #codePointAt(pos) -> uint
474 #trim() -> str, ES6 fix
475 #anchor(name) -> str
476 #big() -> str
477 #blink() -> str
478 #bold() -> str
479 #fixed() -> str
480 #fontcolor(color) -> str
481 #fontsize(size) -> str
482 #italics() -> str
483 #link(url) -> str
484 #small() -> str
485 #strike() -> str
486 #sub() -> str
487 #sup() -> str
488 #@@iterator() -> iterator (code points)
489```
490[*CommonJS entry points:*](#commonjs)
491```
492core-js(/library)/es6/string
493core-js(/library)/fn/string/from-code-point
494core-js(/library)/fn/string/raw
495core-js(/library)/fn/string/includes
496core-js(/library)/fn/string/starts-with
497core-js(/library)/fn/string/ends-with
498core-js(/library)/fn/string/repeat
499core-js(/library)/fn/string/code-point-at
500core-js(/library)/fn/string/trim
501core-js(/library)/fn/string/anchor
502core-js(/library)/fn/string/big
503core-js(/library)/fn/string/blink
504core-js(/library)/fn/string/bold
505core-js(/library)/fn/string/fixed
506core-js(/library)/fn/string/fontcolor
507core-js(/library)/fn/string/fontsize
508core-js(/library)/fn/string/italics
509core-js(/library)/fn/string/link
510core-js(/library)/fn/string/small
511core-js(/library)/fn/string/strike
512core-js(/library)/fn/string/sub
513core-js(/library)/fn/string/sup
514core-js(/library)/fn/string/iterator
515core-js(/library)/fn/string/virtual/includes
516core-js(/library)/fn/string/virtual/starts-with
517core-js(/library)/fn/string/virtual/ends-with
518core-js(/library)/fn/string/virtual/repeat
519core-js(/library)/fn/string/virtual/code-point-at
520core-js(/library)/fn/string/virtual/trim
521core-js(/library)/fn/string/virtual/anchor
522core-js(/library)/fn/string/virtual/big
523core-js(/library)/fn/string/virtual/blink
524core-js(/library)/fn/string/virtual/bold
525core-js(/library)/fn/string/virtual/fixed
526core-js(/library)/fn/string/virtual/fontcolor
527core-js(/library)/fn/string/virtual/fontsize
528core-js(/library)/fn/string/virtual/italics
529core-js(/library)/fn/string/virtual/link
530core-js(/library)/fn/string/virtual/small
531core-js(/library)/fn/string/virtual/strike
532core-js(/library)/fn/string/virtual/sub
533core-js(/library)/fn/string/virtual/sup
534core-js(/library)/fn/string/virtual/iterator
535```
536[*Examples*](http://goo.gl/3UaQ93):
537```js
538for(var val of 'a𠮷b'){
539 console.log(val); // => 'a', '𠮷', 'b'
540}
541
542'foobarbaz'.includes('bar'); // => true
543'foobarbaz'.includes('bar', 4); // => false
544'foobarbaz'.startsWith('foo'); // => true
545'foobarbaz'.startsWith('bar', 3); // => true
546'foobarbaz'.endsWith('baz'); // => true
547'foobarbaz'.endsWith('bar', 6); // => true
548
549'string'.repeat(3); // => 'stringstringstring'
550
551'𠮷'.codePointAt(0); // => 134071
552String.fromCodePoint(97, 134071, 98); // => 'a𠮷b'
553
554var name = 'Bob';
555String.raw`Hi\n${name}!`; // => 'Hi\\nBob!' (ES6 template string syntax)
556String.raw({raw: 'test'}, 0, 1, 2); // => 't0e1s2t'
557
558'foo'.bold(); // => '<b>foo</b>'
559'bar'.anchor('a"b'); // => '<a name="a&quot;b">bar</a>'
560'baz'.link('http://example.com'); // => '<a href="http://example.com">baz</a>'
561```
562#### ECMAScript 6: RegExp
563Modules [`es6.regexp.constructor`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.regexp.constructor.js) and [`es6.regexp.flags`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.regexp.flags.js).
564
565Support well-known [symbols](#ecmascript-6-symbol) `@@match`, `@@replace`, `@@search` and `@@split`, modules [`es6.regexp.match`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.regexp.match.js), [`es6.regexp.replace`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.regexp.replace.js), [`es6.regexp.search`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.regexp.search.js) and [`es6.regexp.split`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.regexp.split.js).
566```
567[new] RegExp(pattern, flags?) -> regexp, ES6 fix: can alter flags (IE9+)
568 #flags -> str (IE9+)
569 #toString() -> str, ES6 fixes
570 #@@match(str) -> array | null
571 #@@replace(str, replacer) -> string
572 #@@search(str) -> index
573 #@@split(str, limit) -> array
574String
575 #match(tpl) -> var, ES6 fix for support @@match
576 #replace(tpl, replacer) -> var, ES6 fix for support @@replace
577 #search(tpl) -> var, ES6 fix for support @@search
578 #split(tpl, limit) -> var, ES6 fix for support @@split, some fixes for old engines
579```
580[*CommonJS entry points:*](#commonjs)
581```
582core-js/es6/regexp
583core-js/fn/regexp/constructor
584core-js(/library)/fn/regexp/flags
585core-js/fn/regexp/to-string
586core-js/fn/regexp/match
587core-js/fn/regexp/replace
588core-js/fn/regexp/search
589core-js/fn/regexp/split
590```
591[*Examples*](http://goo.gl/PiJxBD):
592```js
593RegExp(/./g, 'm'); // => /./m
594
595/foo/.flags; // => ''
596/foo/gim.flags; // => 'gim'
597
598'foo'.match({[Symbol.match]: _ => 1}); // => 1
599'foo'.replace({[Symbol.replace]: _ => 2}); // => 2
600'foo'.search({[Symbol.search]: _ => 3}); // => 3
601'foo'.split({[Symbol.split]: _ => 4}); // => 4
602
603RegExp.prototype.toString.call({source: 'foo', flags: 'bar'}); // => '/foo/bar'
604```
605#### ECMAScript 6: Number
606Module [`es6.number.constructor`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.constructor.js). `Number` constructor support binary and octal literals, [*example*](http://goo.gl/jRd6b3):
607```js
608Number('0b1010101'); // => 85
609Number('0o7654321'); // => 2054353
610```
611Modules [`es6.number.epsilon`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.epsilon.js), [`es6.number.is-finite`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.is-finite.js), [`es6.number.is-integer`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.is-integer.js), [`es6.number.is-nan`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.is-nan.js), [`es6.number.is-safe-integer`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.is-safe-integer.js), [`es6.number.max-safe-integer`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.max-safe-integer.js), [`es6.number.min-safe-integer`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.min-safe-integer.js), [`es6.number.parse-float`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.parse-float.js), [`es6.number.parse-int`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.parse-int.js), [`es6.number.to-fixed`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.to-fixed.js), [`es6.number.to-precision`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.number.to-precision.js), [`es6.parse-int`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.parse-int.js), [`es6.parse-float`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.parse-float.js).
612```js
613[new] Number(var) -> number | number object
614 .isFinite(num) -> bool
615 .isNaN(num) -> bool
616 .isInteger(num) -> bool
617 .isSafeInteger(num) -> bool
618 .parseFloat(str) -> num
619 .parseInt(str) -> int
620 .EPSILON -> num
621 .MAX_SAFE_INTEGER -> int
622 .MIN_SAFE_INTEGER -> int
623 #toFixed(digits) -> string, fixes
624 #toPrecision(precision) -> string, fixes
625parseFloat(str) -> num, fixes
626parseInt(str) -> int, fixes
627```
628[*CommonJS entry points:*](#commonjs)
629```
630core-js(/library)/es6/number
631core-js/es6/number/constructor
632core-js(/library)/fn/number/is-finite
633core-js(/library)/fn/number/is-nan
634core-js(/library)/fn/number/is-integer
635core-js(/library)/fn/number/is-safe-integer
636core-js(/library)/fn/number/parse-float
637core-js(/library)/fn/number/parse-int
638core-js(/library)/fn/number/epsilon
639core-js(/library)/fn/number/max-safe-integer
640core-js(/library)/fn/number/min-safe-integer
641core-js(/library)/fn/number/to-fixed
642core-js(/library)/fn/number/to-precision
643core-js(/library)/fn/parse-float
644core-js(/library)/fn/parse-int
645```
646#### ECMAScript 6: Math
647Modules [`es6.math.acosh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.acosh.js), [`es6.math.asinh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.asinh.js), [`es6.math.atanh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.atanh.js), [`es6.math.cbrt`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.cbrt.js), [`es6.math.clz32`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.clz32.js), [`es6.math.cosh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.cosh.js), [`es6.math.expm1`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.expm1.js), [`es6.math.fround`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.fround.js), [`es6.math.hypot`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.hypot.js), [`es6.math.imul`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.imul.js), [`es6.math.log10`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.log10.js), [`es6.math.log1p`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.log1p.js), [`es6.math.log2`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.log2.js), [`es6.math.sign`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.sign.js), [`es6.math.sinh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.sinh.js), [`es6.math.tanh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.tanh.js), [`es6.math.trunc`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.math.trunc.js).
648```js
649Math
650 .acosh(num) -> num
651 .asinh(num) -> num
652 .atanh(num) -> num
653 .cbrt(num) -> num
654 .clz32(num) -> uint
655 .cosh(num) -> num
656 .expm1(num) -> num
657 .fround(num) -> num
658 .hypot(...args) -> num
659 .imul(num, num) -> int
660 .log1p(num) -> num
661 .log10(num) -> num
662 .log2(num) -> num
663 .sign(num) -> 1 | -1 | 0 | -0 | NaN
664 .sinh(num) -> num
665 .tanh(num) -> num
666 .trunc(num) -> num
667```
668[*CommonJS entry points:*](#commonjs)
669```
670core-js(/library)/es6/math
671core-js(/library)/fn/math/acosh
672core-js(/library)/fn/math/asinh
673core-js(/library)/fn/math/atanh
674core-js(/library)/fn/math/cbrt
675core-js(/library)/fn/math/clz32
676core-js(/library)/fn/math/cosh
677core-js(/library)/fn/math/expm1
678core-js(/library)/fn/math/fround
679core-js(/library)/fn/math/hypot
680core-js(/library)/fn/math/imul
681core-js(/library)/fn/math/log1p
682core-js(/library)/fn/math/log10
683core-js(/library)/fn/math/log2
684core-js(/library)/fn/math/sign
685core-js(/library)/fn/math/sinh
686core-js(/library)/fn/math/tanh
687core-js(/library)/fn/math/trunc
688```
689#### ECMAScript 6: Date
690Modules [`es6.date.to-string`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.date.to-string.js), ES5 features with fixes: [`es6.date.now`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.date.now.js), [`es6.date.to-iso-string`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.date.to-iso-string.js), [`es6.date.to-json`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.date.to-json.js) and [`es6.date.to-primitive`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.date.to-primitive.js).
691```js
692Date
693 .now() -> int
694 #toISOString() -> string
695 #toJSON() -> string
696 #toString() -> string
697 #@@toPrimitive(hint) -> primitive
698```
699[*CommonJS entry points:*](#commonjs)
700```
701core-js/es6/date
702core-js/fn/date/to-string
703core-js(/library)/fn/date/now
704core-js(/library)/fn/date/to-iso-string
705core-js(/library)/fn/date/to-json
706core-js(/library)/fn/date/to-primitive
707```
708[*Example*](http://goo.gl/haeHLR):
709```js
710new Date(NaN).toString(); // => 'Invalid Date'
711```
712
713#### ECMAScript 6: Promise
714Module [`es6.promise`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.promise.js).
715```js
716new Promise(executor(resolve(var), reject(var))) -> promise
717 #then(resolved(var), rejected(var)) -> promise
718 #catch(rejected(var)) -> promise
719 .resolve(promise | var) -> promise
720 .reject(var) -> promise
721 .all(iterable) -> promise
722 .race(iterable) -> promise
723```
724[*CommonJS entry points:*](#commonjs)
725```
726core-js(/library)/es6/promise
727core-js(/library)/fn/promise
728```
729Basic [*example*](http://goo.gl/vGrtUC):
730```js
731function sleepRandom(time){
732 return new Promise(function(resolve, reject){
733 setTimeout(resolve, time * 1e3, 0 | Math.random() * 1e3);
734 });
735}
736
737console.log('Run'); // => Run
738sleepRandom(5).then(function(result){
739 console.log(result); // => 869, after 5 sec.
740 return sleepRandom(10);
741}).then(function(result){
742 console.log(result); // => 202, after 10 sec.
743}).then(function(){
744 console.log('immediately after'); // => immediately after
745 throw Error('Irror!');
746}).then(function(){
747 console.log('will not be displayed');
748}).catch(x => console.log(x)); // => => Error: Irror!
749```
750`Promise.resolve` and `Promise.reject` [*example*](http://goo.gl/vr8TN3):
751```js
752Promise.resolve(42).then(x => console.log(x)); // => 42
753Promise.reject(42).catch(x => console.log(x)); // => 42
754
755Promise.resolve($.getJSON('/data.json')); // => ES6 promise
756```
757`Promise.all` [*example*](http://goo.gl/RdoDBZ):
758```js
759Promise.all([
760 'foo',
761 sleepRandom(5),
762 sleepRandom(15),
763 sleepRandom(10) // after 15 sec:
764]).then(x => console.log(x)); // => ['foo', 956, 85, 382]
765```
766`Promise.race` [*example*](http://goo.gl/L8ovkJ):
767```js
768function timeLimit(promise, time){
769 return Promise.race([promise, new Promise(function(resolve, reject){
770 setTimeout(reject, time * 1e3, Error('Await > ' + time + ' sec'));
771 })]);
772}
773
774timeLimit(sleepRandom(5), 10).then(x => console.log(x)); // => 853, after 5 sec.
775timeLimit(sleepRandom(15), 10).catch(x => console.log(x)); // Error: Await > 10 sec
776```
777ECMAScript 7 [async functions](https://tc39.github.io/ecmascript-asyncawait) [example](http://goo.gl/wnQS4j):
778```js
779var delay = time => new Promise(resolve => setTimeout(resolve, time))
780
781async function sleepRandom(time){
782 await delay(time * 1e3);
783 return 0 | Math.random() * 1e3;
784};
785async function sleepError(time, msg){
786 await delay(time * 1e3);
787 throw Error(msg);
788};
789
790(async () => {
791 try {
792 console.log('Run'); // => Run
793 console.log(await sleepRandom(5)); // => 936, after 5 sec.
794 var [a, b, c] = await Promise.all([
795 sleepRandom(5),
796 sleepRandom(15),
797 sleepRandom(10)
798 ]);
799 console.log(a, b, c); // => 210 445 71, after 15 sec.
800 await sleepError(5, 'Irror!');
801 console.log('Will not be displayed');
802 } catch(e){
803 console.log(e); // => Error: 'Irror!', after 5 sec.
804 }
805})();
806```
807
808##### Unhandled rejection tracking
809
810In Node.js, like in native implementation, available events [`unhandledRejection`](https://nodejs.org/api/process.html#process_event_unhandledrejection) and [`rejectionHandled`](https://nodejs.org/api/process.html#process_event_rejectionhandled):
811```js
812process.on('unhandledRejection', (reason, promise) => console.log('unhandled', reason, promise));
813process.on('rejectionHandled', (promise) => console.log('handled', promise));
814
815var p = Promise.reject(42);
816// unhandled 42 [object Promise]
817
818setTimeout(() => p.catch(_ => _), 1e3);
819// handled [object Promise]
820```
821In a browser on rejection, by default, you will see notify in the console, or you can add a custom handler and a handler on handling unhandled, [*example*](http://goo.gl/Wozskl):
822```js
823window.onunhandledrejection = e => console.log('unhandled', e.reason, e.promise);
824window.onrejectionhandled = e => console.log('handled', e.reason, e.promise);
825
826var p = Promise.reject(42);
827// unhandled 42 [object Promise]
828
829setTimeout(() => p.catch(_ => _), 1e3);
830// handled 42 [object Promise]
831```
832
833#### ECMAScript 6: Symbol
834Module [`es6.symbol`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.symbol.js).
835```js
836Symbol(description?) -> symbol
837 .hasInstance -> @@hasInstance
838 .isConcatSpreadable -> @@isConcatSpreadable
839 .iterator -> @@iterator
840 .match -> @@match
841 .replace -> @@replace
842 .search -> @@search
843 .species -> @@species
844 .split -> @@split
845 .toPrimitive -> @@toPrimitive
846 .toStringTag -> @@toStringTag
847 .unscopables -> @@unscopables
848 .for(key) -> symbol
849 .keyFor(symbol) -> key
850 .useSimple() -> void
851 .useSetter() -> void
852Object
853 .getOwnPropertySymbols(object) -> array
854```
855Also wrapped some methods for correct work with `Symbol` polyfill.
856```js
857Object
858 .create(proto | null, descriptors?) -> object
859 .defineProperty(target, key, desc) -> target
860 .defineProperties(target, descriptors) -> target
861 .getOwnPropertyDescriptor(var, key) -> desc | undefined
862 .getOwnPropertyNames(var) -> array
863 #propertyIsEnumerable(key) -> bool
864JSON
865 .stringify(target, replacer?, space?) -> string | undefined
866```
867[*CommonJS entry points:*](#commonjs)
868```
869core-js(/library)/es6/symbol
870core-js(/library)/fn/symbol
871core-js(/library)/fn/symbol/has-instance
872core-js(/library)/fn/symbol/is-concat-spreadable
873core-js(/library)/fn/symbol/iterator
874core-js(/library)/fn/symbol/match
875core-js(/library)/fn/symbol/replace
876core-js(/library)/fn/symbol/search
877core-js(/library)/fn/symbol/species
878core-js(/library)/fn/symbol/split
879core-js(/library)/fn/symbol/to-primitive
880core-js(/library)/fn/symbol/to-string-tag
881core-js(/library)/fn/symbol/unscopables
882core-js(/library)/fn/symbol/for
883core-js(/library)/fn/symbol/key-for
884```
885[*Basic example*](http://goo.gl/BbvWFc):
886```js
887var Person = (function(){
888 var NAME = Symbol('name');
889 function Person(name){
890 this[NAME] = name;
891 }
892 Person.prototype.getName = function(){
893 return this[NAME];
894 };
895 return Person;
896})();
897
898var person = new Person('Vasya');
899console.log(person.getName()); // => 'Vasya'
900console.log(person['name']); // => undefined
901console.log(person[Symbol('name')]); // => undefined, symbols are uniq
902for(var key in person)console.log(key); // => only 'getName', symbols are not enumerable
903```
904`Symbol.for` & `Symbol.keyFor` [*example*](http://goo.gl/0pdJjX):
905```js
906var symbol = Symbol.for('key');
907symbol === Symbol.for('key'); // true
908Symbol.keyFor(symbol); // 'key'
909```
910[*Example*](http://goo.gl/mKVOQJ) with methods for getting own object keys:
911```js
912var O = {a: 1};
913Object.defineProperty(O, 'b', {value: 2});
914O[Symbol('c')] = 3;
915Object.keys(O); // => ['a']
916Object.getOwnPropertyNames(O); // => ['a', 'b']
917Object.getOwnPropertySymbols(O); // => [Symbol(c)]
918Reflect.ownKeys(O); // => ['a', 'b', Symbol(c)]
919```
920##### Caveats when using `Symbol` polyfill:
921
922* We can't add new primitive type, `Symbol` returns object.
923* `Symbol.for` and `Symbol.keyFor` can't be shimmed cross-realm.
924* By default, to hide the keys, `Symbol` polyfill defines setter in `Object.prototype`. For this reason, uncontrolled creation of symbols can cause memory leak and the `in` operator is not working correctly with `Symbol` polyfill: `Symbol() in {} // => true`.
925
926You can disable defining setters in `Object.prototype`. [Example](http://goo.gl/N5UD7J):
927```js
928Symbol.useSimple();
929var s1 = Symbol('s1')
930 , o1 = {};
931o1[s1] = true;
932for(var key in o1)console.log(key); // => 'Symbol(s1)_t.qamkg9f3q', w/o native Symbol
933
934Symbol.useSetter();
935var s2 = Symbol('s2')
936 , o2 = {};
937o2[s2] = true;
938for(var key in o2)console.log(key); // nothing
939```
940* Currently, `core-js` not adds setters to `Object.prototype` for well-known symbols for correct work something like `Symbol.iterator in foo`. It can cause problems with their enumerability.
941* Some problems possible with environment exotic objects (for example, IE `localStorage`).
942
943#### ECMAScript 6: Collections
944`core-js` uses native collections in most case, just fixes methods / constructor, if it's required, and in old environment uses fast polyfill (O(1) lookup).
945#### Map
946Module [`es6.map`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.map.js).
947```js
948new Map(iterable (entries) ?) -> map
949 #clear() -> void
950 #delete(key) -> bool
951 #forEach(fn(val, key, @), that) -> void
952 #get(key) -> val
953 #has(key) -> bool
954 #set(key, val) -> @
955 #size -> uint
956 #values() -> iterator
957 #keys() -> iterator
958 #entries() -> iterator
959 #@@iterator() -> iterator (entries)
960```
961[*CommonJS entry points:*](#commonjs)
962```
963core-js(/library)/es6/map
964core-js(/library)/fn/map
965```
966[*Examples*](http://goo.gl/GWR7NI):
967```js
968var a = [1];
969
970var map = new Map([['a', 1], [42, 2]]);
971map.set(a, 3).set(true, 4);
972
973console.log(map.size); // => 4
974console.log(map.has(a)); // => true
975console.log(map.has([1])); // => false
976console.log(map.get(a)); // => 3
977map.forEach(function(val, key){
978 console.log(val); // => 1, 2, 3, 4
979 console.log(key); // => 'a', 42, [1], true
980});
981map.delete(a);
982console.log(map.size); // => 3
983console.log(map.get(a)); // => undefined
984console.log(Array.from(map)); // => [['a', 1], [42, 2], [true, 4]]
985
986var map = new Map([['a', 1], ['b', 2], ['c', 3]]);
987
988for(var [key, val] of map){
989 console.log(key); // => 'a', 'b', 'c'
990 console.log(val); // => 1, 2, 3
991}
992for(var val of map.values())console.log(val); // => 1, 2, 3
993for(var key of map.keys())console.log(key); // => 'a', 'b', 'c'
994for(var [key, val] of map.entries()){
995 console.log(key); // => 'a', 'b', 'c'
996 console.log(val); // => 1, 2, 3
997}
998```
999#### Set
1000Module [`es6.set`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.set.js).
1001```js
1002new Set(iterable?) -> set
1003 #add(key) -> @
1004 #clear() -> void
1005 #delete(key) -> bool
1006 #forEach(fn(el, el, @), that) -> void
1007 #has(key) -> bool
1008 #size -> uint
1009 #values() -> iterator
1010 #keys() -> iterator
1011 #entries() -> iterator
1012 #@@iterator() -> iterator (values)
1013```
1014[*CommonJS entry points:*](#commonjs)
1015```
1016core-js(/library)/es6/set
1017core-js(/library)/fn/set
1018```
1019[*Examples*](http://goo.gl/bmhLwg):
1020```js
1021var set = new Set(['a', 'b', 'a', 'c']);
1022set.add('d').add('b').add('e');
1023console.log(set.size); // => 5
1024console.log(set.has('b')); // => true
1025set.forEach(function(it){
1026 console.log(it); // => 'a', 'b', 'c', 'd', 'e'
1027});
1028set.delete('b');
1029console.log(set.size); // => 4
1030console.log(set.has('b')); // => false
1031console.log(Array.from(set)); // => ['a', 'c', 'd', 'e']
1032
1033var set = new Set([1, 2, 3, 2, 1]);
1034
1035for(var val of set)console.log(val); // => 1, 2, 3
1036for(var val of set.values())console.log(val); // => 1, 2, 3
1037for(var key of set.keys())console.log(key); // => 1, 2, 3
1038for(var [key, val] of set.entries()){
1039 console.log(key); // => 1, 2, 3
1040 console.log(val); // => 1, 2, 3
1041}
1042```
1043#### WeakMap
1044Module [`es6.weak-map`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.weak-map.js).
1045```js
1046new WeakMap(iterable (entries) ?) -> weakmap
1047 #delete(key) -> bool
1048 #get(key) -> val
1049 #has(key) -> bool
1050 #set(key, val) -> @
1051```
1052[*CommonJS entry points:*](#commonjs)
1053```
1054core-js(/library)/es6/weak-map
1055core-js(/library)/fn/weak-map
1056```
1057[*Examples*](http://goo.gl/SILXyw):
1058```js
1059var a = [1]
1060 , b = [2]
1061 , c = [3];
1062
1063var wmap = new WeakMap([[a, 1], [b, 2]]);
1064wmap.set(c, 3).set(b, 4);
1065console.log(wmap.has(a)); // => true
1066console.log(wmap.has([1])); // => false
1067console.log(wmap.get(a)); // => 1
1068wmap.delete(a);
1069console.log(wmap.get(a)); // => undefined
1070
1071// Private properties store:
1072var Person = (function(){
1073 var names = new WeakMap;
1074 function Person(name){
1075 names.set(this, name);
1076 }
1077 Person.prototype.getName = function(){
1078 return names.get(this);
1079 };
1080 return Person;
1081})();
1082
1083var person = new Person('Vasya');
1084console.log(person.getName()); // => 'Vasya'
1085for(var key in person)console.log(key); // => only 'getName'
1086```
1087#### WeakSet
1088Module [`es6.weak-set`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.weak-set.js).
1089```js
1090new WeakSet(iterable?) -> weakset
1091 #add(key) -> @
1092 #delete(key) -> bool
1093 #has(key) -> bool
1094```
1095[*CommonJS entry points:*](#commonjs)
1096```
1097core-js(/library)/es6/weak-set
1098core-js(/library)/fn/weak-set
1099```
1100[*Examples*](http://goo.gl/TdFbEx):
1101```js
1102var a = [1]
1103 , b = [2]
1104 , c = [3];
1105
1106var wset = new WeakSet([a, b, a]);
1107wset.add(c).add(b).add(c);
1108console.log(wset.has(b)); // => true
1109console.log(wset.has([2])); // => false
1110wset.delete(b);
1111console.log(wset.has(b)); // => false
1112```
1113##### Caveats when using collections polyfill:
1114
1115* Weak-collections polyfill stores values as hidden properties of keys. It works correct and not leak in most cases. However, it is desirable to store a collection longer than its keys.
1116
1117#### ECMAScript 6: Typed Arrays
1118Implementations and fixes `ArrayBuffer`, `DataView`, typed arrays constructors, static and prototype methods. Typed Arrays work only in environments with support descriptors (IE9+), `ArrayBuffer` and `DataView` should work anywhere.
1119
1120Modules [`es6.typed.array-buffer`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.array-buffer.js), [`es6.typed.data-view`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.data-view.js), [`es6.typed.int8-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.int8-array.js), [`es6.typed.uint8-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.uint8-array.js), [`es6.typed.uint8-clamped-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.uint8-clamped-array.js), [`es6.typed.int16-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.int16-array.js), [`es6.typed.uint16-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.uint16-array.js), [`es6.typed.int32-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.int32-array.js), [`es6.typed.uint32-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.uint32-array.js), [`es6.typed.float32-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.float32-array.js) and [`es6.typed.float64-array`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.typed.float64-array.js).
1121```js
1122new ArrayBuffer(length) -> buffer
1123 .isView(var) -> bool
1124 #slice(start = 0, end = @length) -> buffer
1125 #byteLength -> uint
1126
1127new DataView(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) -> view
1128 #getInt8(offset) -> int8
1129 #getUint8(offset) -> uint8
1130 #getInt16(offset, littleEndian = false) -> int16
1131 #getUint16(offset, littleEndian = false) -> uint16
1132 #getInt32(offset, littleEndian = false) -> int32
1133 #getUint32(offset, littleEndian = false) -> uint32
1134 #getFloat32(offset, littleEndian = false) -> float32
1135 #getFloat64(offset, littleEndian = false) -> float64
1136 #setInt8(offset, value) -> void
1137 #setUint8(offset, value) -> void
1138 #setInt16(offset, value, littleEndian = false) -> void
1139 #setUint16(offset, value, littleEndian = false) -> void
1140 #setInt32(offset, value, littleEndian = false) -> void
1141 #setUint32(offset, value, littleEndian = false) -> void
1142 #setFloat32(offset, value, littleEndian = false) -> void
1143 #setFloat64(offset, value, littleEndian = false) -> void
1144 #buffer -> buffer
1145 #byteLength -> uint
1146 #byteOffset -> uint
1147
1148{
1149 Int8Array,
1150 Uint8Array,
1151 Uint8ClampedArray,
1152 Int16Array,
1153 Uint16Array,
1154 Int32Array,
1155 Uint32Array,
1156 Float32Array,
1157 Float64Array
1158}
1159 new %TypedArray%(length) -> typed
1160 new %TypedArray%(typed) -> typed
1161 new %TypedArray%(arrayLike) -> typed
1162 new %TypedArray%(iterable) -> typed
1163 new %TypedArray%(buffer, byteOffset = 0, length = (buffer.byteLength - byteOffset) / @BYTES_PER_ELEMENT) -> typed
1164 .BYTES_PER_ELEMENT -> uint
1165 .from(arrayLike | iterable, mapFn(val, index)?, that) -> typed
1166 .of(...args) -> typed
1167 #BYTES_PER_ELEMENT -> uint
1168 #copyWithin(target = 0, start = 0, end = @length) -> @
1169 #every(fn(val, index, @), that) -> bool
1170 #fill(val, start = 0, end = @length) -> @
1171 #filter(fn(val, index, @), that) -> typed
1172 #find(fn(val, index, @), that) -> val
1173 #findIndex(fn(val, index, @), that) -> index
1174 #forEach(fn(val, index, @), that) -> void
1175 #indexOf(var, from?) -> int
1176 #join(string = ',') -> string
1177 #lastIndexOf(var, from?) -> int
1178 #map(fn(val, index, @), that) -> typed
1179 #reduce(fn(memo, val, index, @), memo?) -> var
1180 #reduceRight(fn(memo, val, index, @), memo?) -> var
1181 #reverse() -> @
1182 #set(arrayLike, offset = 0) -> void
1183 #slice(start = 0, end = @length) -> typed
1184 #some(fn(val, index, @), that) -> bool
1185 #sort(fn(a, b)?) -> @
1186 #subarray(start = 0, end = @length) -> typed
1187 #toString() -> string
1188 #toLocaleString() -> string
1189 #values() -> iterator
1190 #keys() -> iterator
1191 #entries() -> iterator
1192 #@@iterator() -> iterator (values)
1193 #buffer -> buffer
1194 #byteLength -> uint
1195 #byteOffset -> uint
1196 #length -> uint
1197```
1198[*CommonJS entry points:*](#commonjs)
1199```
1200core-js(/library)/es6/typed
1201core-js(/library)/fn/typed
1202core-js(/library)/fn/typed/array-buffer
1203core-js(/library)/fn/typed/data-view
1204core-js(/library)/fn/typed/int8-array
1205core-js(/library)/fn/typed/uint8-array
1206core-js(/library)/fn/typed/uint8-clamped-array
1207core-js(/library)/fn/typed/int16-array
1208core-js(/library)/fn/typed/uint16-array
1209core-js(/library)/fn/typed/int32-array
1210core-js(/library)/fn/typed/uint32-array
1211core-js(/library)/fn/typed/float32-array
1212core-js(/library)/fn/typed/float64-array
1213```
1214[*Examples*](http://goo.gl/yla75z):
1215```js
1216new Int32Array(4); // => [0, 0, 0, 0]
1217new Uint8ClampedArray([1, 2, 3, 666]); // => [1, 2, 3, 255]
1218new Float32Array(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
1219
1220var buffer = new ArrayBuffer(8);
1221var view = new DataView(buffer);
1222view.setFloat64(0, 123.456, true);
1223new Uint8Array(buffer.slice(4)); // => [47, 221, 94, 64]
1224
1225Int8Array.of(1, 1.5, 5.7, 745); // => [1, 1, 5, -23]
1226Uint8Array.from([1, 1.5, 5.7, 745]); // => [1, 1, 5, 233]
1227
1228var typed = new Uint8Array([1, 2, 3]);
1229
1230var a = typed.slice(1); // => [2, 3]
1231typed.buffer === a.buffer; // => false
1232var b = typed.subarray(1); // => [2, 3]
1233typed.buffer === b.buffer; // => true
1234
1235typed.filter(it => it % 2); // => [1, 3]
1236typed.map(it => it * 1.5); // => [1, 3, 4]
1237
1238for(var val of typed)console.log(val); // => 1, 2, 3
1239for(var val of typed.values())console.log(val); // => 1, 2, 3
1240for(var key of typed.keys())console.log(key); // => 0, 1, 2
1241for(var [key, val] of typed.entries()){
1242 console.log(key); // => 0, 1, 2
1243 console.log(val); // => 1, 2, 3
1244}
1245```
1246##### Caveats when using typed arrays:
1247
1248* Typed Arrays polyfills works completely how should work by the spec, but because of internal use getter / setters on each instance, is slow and consumes significant memory. However, typed arrays polyfills required mainly for IE9 (and for `Uint8ClampedArray` in IE10 and early IE11), all modern engines have native typed arrays and requires only constructors fixes and methods.
1249* The current version hasn't special entry points for methods, they can be added only with constructors. It can be added in the future.
1250* In the `library` version we can't pollute native prototypes, so prototype methods available as constructors static.
1251
1252#### ECMAScript 6: Reflect
1253Modules [`es6.reflect.apply`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.apply.js), [`es6.reflect.construct`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.construct.js), [`es6.reflect.define-property`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.define-property.js), [`es6.reflect.delete-property`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.delete-property.js), [`es6.reflect.enumerate`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.enumerate.js), [`es6.reflect.get`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.get.js), [`es6.reflect.get-own-property-descriptor`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.get-own-property-descriptor.js), [`es6.reflect.get-prototype-of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.get-prototype-of.js), [`es6.reflect.has`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.has.js), [`es6.reflect.is-extensible`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.is-extensible.js), [`es6.reflect.own-keys`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.own-keys.js), [`es6.reflect.prevent-extensions`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.prevent-extensions.js), [`es6.reflect.set`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.set.js), [`es6.reflect.set-prototype-of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es6.reflect.set-prototype-of.js).
1254```js
1255Reflect
1256 .apply(target, thisArgument, argumentsList) -> var
1257 .construct(target, argumentsList, newTarget?) -> object
1258 .defineProperty(target, propertyKey, attributes) -> bool
1259 .deleteProperty(target, propertyKey) -> bool
1260 .enumerate(target) -> iterator (removed from the spec and will be removed from core-js@3)
1261 .get(target, propertyKey, receiver?) -> var
1262 .getOwnPropertyDescriptor(target, propertyKey) -> desc
1263 .getPrototypeOf(target) -> object | null
1264 .has(target, propertyKey) -> bool
1265 .isExtensible(target) -> bool
1266 .ownKeys(target) -> array
1267 .preventExtensions(target) -> bool
1268 .set(target, propertyKey, V, receiver?) -> bool
1269 .setPrototypeOf(target, proto) -> bool (required __proto__ - IE11+)
1270```
1271[*CommonJS entry points:*](#commonjs)
1272```
1273core-js(/library)/es6/reflect
1274core-js(/library)/fn/reflect
1275core-js(/library)/fn/reflect/apply
1276core-js(/library)/fn/reflect/construct
1277core-js(/library)/fn/reflect/define-property
1278core-js(/library)/fn/reflect/delete-property
1279core-js(/library)/fn/reflect/enumerate (deprecated and will be removed from the next major release)
1280core-js(/library)/fn/reflect/get
1281core-js(/library)/fn/reflect/get-own-property-descriptor
1282core-js(/library)/fn/reflect/get-prototype-of
1283core-js(/library)/fn/reflect/has
1284core-js(/library)/fn/reflect/is-extensible
1285core-js(/library)/fn/reflect/own-keys
1286core-js(/library)/fn/reflect/prevent-extensions
1287core-js(/library)/fn/reflect/set
1288core-js(/library)/fn/reflect/set-prototype-of
1289```
1290[*Examples*](http://goo.gl/gVT0cH):
1291```js
1292var O = {a: 1};
1293Object.defineProperty(O, 'b', {value: 2});
1294O[Symbol('c')] = 3;
1295Reflect.ownKeys(O); // => ['a', 'b', Symbol(c)]
1296
1297function C(a, b){
1298 this.c = a + b;
1299}
1300
1301var instance = Reflect.construct(C, [20, 22]);
1302instance.c; // => 42
1303```
1304
1305### ECMAScript 7+ proposals
1306[The TC39 process.](https://tc39.github.io/process-document/)
1307
1308[*CommonJS entry points:*](#commonjs)
1309```
1310core-js(/library)/es7
1311core-js(/library)/es7/array
1312core-js(/library)/es7/global
1313core-js(/library)/es7/string
1314core-js(/library)/es7/map
1315core-js(/library)/es7/set
1316core-js(/library)/es7/error
1317core-js(/library)/es7/math
1318core-js(/library)/es7/system
1319core-js(/library)/es7/symbol
1320core-js(/library)/es7/reflect
1321core-js(/library)/es7/observable
1322```
1323`core-js/stage/4` entry point contains only stage 4 proposals, `core-js/stage/3` - stage 3 and stage 4, etc.
1324#### Stage 4 proposals
1325
1326[*CommonJS entry points:*](#commonjs)
1327```js
1328core-js(/library)/stage/4
1329```
1330* `{Array, %TypedArray%}#includes` [proposal](https://github.com/tc39/Array.prototype.includes) - module [`es7.array.includes`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.array.includes.js), `%TypedArray%` version in modules from [this section](#ecmascript-6-typed-arrays).
1331```js
1332Array
1333 #includes(var, from?) -> bool
1334{
1335 Int8Array,
1336 Uint8Array,
1337 Uint8ClampedArray,
1338 Int16Array,
1339 Uint16Array,
1340 Int32Array,
1341 Uint32Array,
1342 Float32Array,
1343 Float64Array
1344}
1345 #includes(var, from?) -> bool
1346```
1347[*CommonJS entry points:*](#commonjs)
1348```js
1349core-js(/library)/fn/array/includes
1350```
1351[*Examples*](http://goo.gl/2Gq4ma):
1352```js
1353[1, 2, 3].includes(2); // => true
1354[1, 2, 3].includes(4); // => false
1355[1, 2, 3].includes(2, 2); // => false
1356
1357[NaN].indexOf(NaN); // => -1
1358[NaN].includes(NaN); // => true
1359Array(1).indexOf(undefined); // => -1
1360Array(1).includes(undefined); // => true
1361```
1362* `Object.values`, `Object.entries` [proposal](https://github.com/tc39/proposal-object-values-entries) - modules [`es7.object.values`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.object.values.js), [`es7.object.entries`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.object.entries.js)
1363```js
1364Object
1365 .values(object) -> array
1366 .entries(object) -> array
1367```
1368[*CommonJS entry points:*](#commonjs)
1369```js
1370core-js(/library)/fn/object/values
1371core-js(/library)/fn/object/entries
1372```
1373[*Examples*](http://goo.gl/6kuGOn):
1374```js
1375Object.values({a: 1, b: 2, c: 3}); // => [1, 2, 3]
1376Object.entries({a: 1, b: 2, c: 3}); // => [['a', 1], ['b', 2], ['c', 3]]
1377
1378for(let [key, value] of Object.entries({a: 1, b: 2, c: 3})){
1379 console.log(key); // => 'a', 'b', 'c'
1380 console.log(value); // => 1, 2, 3
1381}
1382```
1383* `Object.getOwnPropertyDescriptors` [proposal](https://github.com/tc39/proposal-object-getownpropertydescriptors) - module [`es7.object.get-own-property-descriptors`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.object.get-own-property-descriptors.js)
1384```js
1385Object
1386 .getOwnPropertyDescriptors(object) -> object
1387```
1388[*CommonJS entry points:*](#commonjs)
1389```js
1390core-js(/library)/fn/object/get-own-property-descriptors
1391```
1392*Examples*:
1393```js
1394// Shallow object cloning with prototype and descriptors:
1395var copy = Object.create(Object.getPrototypeOf(O), Object.getOwnPropertyDescriptors(O));
1396// Mixin:
1397Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
1398```
1399* `String#padStart`, `String#padEnd` [proposal](https://github.com/tc39/proposal-string-pad-start-end) - modules [`es7.string.pad-start`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.string.pad-start.js), [`es7.string.pad-end`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.string.pad-end.js)
1400```js
1401String
1402 #padStart(length, fillStr = ' ') -> string
1403 #padEnd(length, fillStr = ' ') -> string
1404```
1405[*CommonJS entry points:*](#commonjs)
1406```js
1407core-js(/library)/fn/string/pad-start
1408core-js(/library)/fn/string/pad-end
1409core-js(/library)/fn/string/virtual/pad-start
1410core-js(/library)/fn/string/virtual/pad-end
1411```
1412[*Examples*](http://goo.gl/hK5ccv):
1413```js
1414'hello'.padStart(10); // => ' hello'
1415'hello'.padStart(10, '1234'); // => '12341hello'
1416'hello'.padEnd(10); // => 'hello '
1417'hello'.padEnd(10, '1234'); // => 'hello12341'
1418```
1419* `Object#__(define|lookup)[GS]etter__`, [annex B ES2017](https://github.com/tc39/ecma262/pull/381), but we haven't special namespace for that - modules [`es7.object.define-setter`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.object.define-setter.js), [`es7.object.define-getter`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.object.define-getter.js), [`es7.object.lookup-setter`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.object.lookup-setter.js) and [`es7.object.lookup-getter`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.object.lookup-getter.js).
1420```js
1421Object
1422 #__defineSetter__(key, fn) -> void
1423 #__defineGetter__(key, fn) -> void
1424 #__lookupSetter__(key) -> fn | void
1425 #__lookupGetter__(key) -> fn | void
1426```
1427[*CommonJS entry points:*](#commonjs)
1428```js
1429core-js(/library)/fn/object/define-getter
1430core-js(/library)/fn/object/define-setter
1431core-js(/library)/fn/object/lookup-getter
1432core-js(/library)/fn/object/lookup-setter
1433```
1434
1435#### Stage 3 proposals
1436[*CommonJS entry points:*](#commonjs)
1437```js
1438core-js(/library)/stage/3
1439```
1440* `global` [proposal](https://github.com/tc39/proposal-global) - modules [`es7.global`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.global.js) and [`es7.system.global`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.system.global.js) (obsolete)
1441```js
1442global -> object
1443System
1444 .global -> object (obsolete)
1445```
1446[*CommonJS entry points:*](#commonjs)
1447```js
1448core-js(/library)/fn/global
1449core-js(/library)/fn/system/global (obsolete)
1450```
1451[*Examples*](http://goo.gl/gEqMl7):
1452```js
1453global.Array === Array; // => true
1454```
1455* `Promise#finally` [proposal](https://github.com/tc39/proposal-promise-finally) - module [`es7.promise.finally`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.promise.finally.js)
1456```js
1457Promise
1458 #finally(onFinally()) -> promise
1459```
1460[*CommonJS entry points:*](#commonjs)
1461```js
1462core-js(/library)/fn/promise/finally
1463```
1464[*Examples*](https://goo.gl/AhyBbJ):
1465```js
1466Promise.resolve(42).finally(() => console.log('You will see it anyway'));
1467
1468Promise.reject(42).finally(() => console.log('You will see it anyway'));
1469
1470#### Stage 2 proposals
1471[*CommonJS entry points:*](#commonjs)
1472```js
1473core-js(/library)/stage/2
1474```
1475* `String#trimLeft`, `String#trimRight` / `String#trimStart`, `String#trimEnd` [proposal](https://github.com/sebmarkbage/ecmascript-string-left-right-trim) - modules [`es7.string.trim-left`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.string.trim-right.js), [`es7.string.trim-right`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.string.trim-right.js)
1476```js
1477String
1478 #trimLeft() -> string
1479 #trimRight() -> string
1480 #trimStart() -> string
1481 #trimEnd() -> string
1482```
1483[*CommonJS entry points:*](#commonjs)
1484```js
1485core-js(/library)/fn/string/trim-start
1486core-js(/library)/fn/string/trim-end
1487core-js(/library)/fn/string/trim-left
1488core-js(/library)/fn/string/trim-right
1489core-js(/library)/fn/string/virtual/trim-start
1490core-js(/library)/fn/string/virtual/trim-end
1491core-js(/library)/fn/string/virtual/trim-left
1492core-js(/library)/fn/string/virtual/trim-right
1493```
1494[*Examples*](http://goo.gl/Er5lMJ):
1495```js
1496' hello '.trimLeft(); // => 'hello '
1497' hello '.trimRight(); // => ' hello'
1498```
1499```
1500* `Symbol.asyncIterator` for [async iteration proposal](https://github.com/tc39/proposal-async-iteration) - module [`es7.symbol.async-iterator`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.symbol.async-iterator.js)
1501```js
1502Symbol
1503 .asyncIterator -> @@asyncIterator
1504```
1505[*CommonJS entry points:*](#commonjs)
1506```js
1507core-js(/library)/fn/symbol/async-iterator
1508```
1509
1510#### Stage 1 proposals
1511[*CommonJS entry points:*](#commonjs)
1512```js
1513core-js(/library)/stage/1
1514```
1515* `Promise.try` [proposal](https://github.com/tc39/proposal-promise-try) - module [`es7.promise.try`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.promise.try.js)
1516```js
1517Promise
1518 .try(function()) -> promise
1519```
1520[*CommonJS entry points:*](#commonjs)
1521```js
1522core-js(/library)/fn/promise/try
1523```
1524[*Examples*](https://goo.gl/k5GGRo):
1525```js
1526Promise.try(() => 42).then(it => console.log(`Promise, resolved as ${it}`));
1527
1528Promise.try(() => { throw 42; }).catch(it => console.log(`Promise, rejected as ${it}`));
1529```
1530* `Array#flatten` and `Array#flatMap` [proposal](https://tc39.github.io/proposal-flatMap) - modules [`es7.array.flatten`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.array.flatten.js) and [`es7.array.flat-map`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.array.flat-map.js)
1531```js
1532Array
1533 #flatten(depthArg = 1) -> array
1534 #flatMap(fn(val, key, @), that) -> array
1535```
1536[*CommonJS entry points:*](#commonjs)
1537```js
1538core-js(/library)/fn/array/flatten
1539core-js(/library)/fn/array/flat-map
1540core-js(/library)/fn/array/virtual/flatten
1541core-js(/library)/fn/array/virtual/flat-map
1542```
1543[*Examples*](https://goo.gl/jTXsZi):
1544```js
1545[1, [2, 3], [4, 5]].flatten(); // => [1, 2, 3, 4, 5]
1546[1, [2, [3, [4]]], 5].flatten(); // => [1, 2, [3, [4]], 5]
1547[1, [2, [3, [4]]], 5].flatten(3); // => [1, 2, 3, 4, 5]
1548
1549[{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}].flatMap(it => [it.a, it.b]); // => [1, 2, 3, 4, 5, 6]
1550```
1551* `.of` and `.from` methods on collection constructors [proposal](https://github.com/tc39/proposal-setmap-offrom) - modules [`es7.set.of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.set.of.js), [`es7.set.from`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.set.from.js), [`es7.map.of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.map.of.js), [`es7.map.from`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.map.from.js), [`es7.weak-set.of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.weak-set.of.js), [`es7.weak-set.from`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.weak-set.from.js), [`es7.weak-map.of`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.weak-map.of.js), [`es7.weak-map.from`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.weak-map.from.js)
1552```js
1553Set
1554 .of(...args) -> set
1555 .from(iterable, mapFn(val, index)?, that?) -> set
1556Map
1557 .of(...args) -> map
1558 .from(iterable, mapFn(val, index)?, that?) -> map
1559WeakSet
1560 .of(...args) -> weakset
1561 .from(iterable, mapFn(val, index)?, that?) -> weakset
1562WeakMap
1563 .of(...args) -> weakmap
1564 .from(iterable, mapFn(val, index)?, that?) -> weakmap
1565```
1566[*CommonJS entry points:*](#commonjs)
1567```js
1568core-js(/library)/fn/set/of
1569core-js(/library)/fn/set/from
1570core-js(/library)/fn/map/of
1571core-js(/library)/fn/map/from
1572core-js(/library)/fn/weak-set/of
1573core-js(/library)/fn/weak-set/from
1574core-js(/library)/fn/weak-map/of
1575core-js(/library)/fn/weak-map/from
1576```
1577[*Examples*](https://goo.gl/mSC7eU):
1578```js
1579Set.of(1, 2, 3, 2, 1); // => Set {1, 2, 3}
1580
1581Map.from([[1, 2], [3, 4]], ([key, val]) => [key ** 2, val ** 2]); // => Map {1: 4, 9: 16}
1582```
1583* `String#matchAll` [proposal](https://github.com/tc39/String.prototype.matchAll) - module [`es7.string.match-all`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.string.match-all.js)
1584```js
1585String
1586 #matchAll(regexp) -> iterator
1587```
1588[*CommonJS entry points:*](#commonjs)
1589```js
1590core-js(/library)/fn/string/match-all
1591core-js(/library)/fn/string/virtual/match-all
1592```
1593[*Examples*](http://goo.gl/6kp9EB):
1594```js
1595for(let [_, d, D] of '1111a2b3cccc'.matchAll(/(\d)(\D)/)){
1596 console.log(d, D); // => 1 a, 2 b, 3 c
1597}
1598```
1599* `Observable` [proposal](https://github.com/zenparsing/es-observable) - modules [`es7.observable`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.observable.js) and [`es7.symbol.observable`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.symbol.observable.js)
1600```js
1601new Observable(fn) -> observable
1602 #subscribe(observer) -> subscription
1603 #forEach(fn) -> promise
1604 #@@observable() -> @
1605 .of(...items) -> observable
1606 .from(observable | iterable) -> observable
1607 .@@species -> @
1608Symbol
1609 .observable -> @@observable
1610```
1611[*CommonJS entry points:*](#commonjs)
1612```js
1613core-js(/library)/fn/observable
1614core-js(/library)/fn/symbol/observable
1615```
1616[*Examples*](http://goo.gl/1LDywi):
1617```js
1618new Observable(observer => {
1619 observer.next('hello');
1620 observer.next('world');
1621 observer.complete();
1622}).forEach(it => console.log(it))
1623 .then(_ => console.log('!'));
1624```
1625* `Math.{clamp, DEG_PER_RAD, degrees, fscale, rad-per-deg, radians, scale}`
1626 [proposal](https://github.com/rwaldron/proposal-math-extensions) - modules
1627 [`es7.math.clamp`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.clamp.js),
1628 [`es7.math.DEG_PER_RAD`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.DEG_PER_RAD.js),
1629 [`es7.math.degrees`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.degrees.js),
1630 [`es7.math.fscale`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.fscale.js),
1631 [`es7.math.RAD_PER_DEG`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.RAD_PER_DEG.js),
1632 [`es7.math.radians`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.radians.js) and
1633 [`es7.math.scale`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.scale.js)
1634```js
1635Math
1636 .DEG_PER_RAD -> number
1637 .RAD_PER_DEG -> number
1638 .clamp(x, lower, upper) -> number
1639 .degrees(radians) -> number
1640 .fscale(x, inLow, inHigh, outLow, outHigh) -> number
1641 .radians(degrees) -> number
1642 .scale(x, inLow, inHigh, outLow, outHigh) -> number
1643```
1644[*CommonJS entry points:*](#commonjs)
1645```js
1646core-js(/library)/fn/math/clamp
1647core-js(/library)/fn/math/deg-per-rad
1648core-js(/library)/fn/math/degrees
1649core-js(/library)/fn/math/fscale
1650core-js(/library)/fn/math/rad-per-deg
1651core-js(/library)/fn/math/radians
1652core-js(/library)/fn/math/scale
1653```
1654* `Math.signbit` [proposal](http://jfbastien.github.io/papers/Math.signbit.html) - module [`es7.math.signbit`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.signbit.js)
1655```js
1656Math
1657 .signbit(x) -> bool
1658```
1659[*CommonJS entry points:*](#commonjs)
1660```js
1661core-js(/library)/fn/math/signbit
1662```
1663[*Examples*](http://es6.zloirock.ru/):
1664```js
1665Math.signbit(NaN); // => NaN
1666Math.signbit(1); // => true
1667Math.signbit(-1); // => false
1668Math.signbit(0); // => true
1669Math.signbit(-0); // => false
1670```
1671
1672#### Stage 0 proposals
1673[*CommonJS entry points:*](#commonjs)
1674```js
1675core-js(/library)/stage/0
1676```
1677* `String#at` [proposal](https://github.com/mathiasbynens/String.prototype.at) - module [`es7.string.at`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.string.at.js)
1678```js
1679String
1680 #at(index) -> string
1681```
1682[*CommonJS entry points:*](#commonjs)
1683```js
1684core-js(/library)/fn/string/at
1685core-js(/library)/fn/string/virtual/at
1686```
1687[*Examples*](http://goo.gl/XluXI8):
1688```js
1689'a𠮷b'.at(1); // => '𠮷'
1690'a𠮷b'.at(1).length; // => 2
1691```
1692* `Map#toJSON`, `Set#toJSON` [proposal](https://github.com/DavidBruant/Map-Set.prototype.toJSON) - modules [`es7.map.to-json`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.map.to-json.js), [`es7.set.to-json`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.set.to-json.js) (rejected and will be removed from `core-js@3`)
1693```js
1694Map
1695 #toJSON() -> array (rejected and will be removed from core-js@3)
1696Set
1697 #toJSON() -> array (rejected and will be removed from core-js@3)
1698```
1699[*CommonJS entry points:*](#commonjs)
1700```js
1701core-js(/library)/fn/map
1702core-js(/library)/fn/set
1703```
1704* `Error.isError` [proposal](https://github.com/ljharb/proposal-is-error) - module [`es7.error.is-error`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.error.is-error.js) (withdrawn and will be removed from `core-js@3`)
1705```js
1706Error
1707 .isError(it) -> bool (withdrawn and will be removed from core-js@3)
1708```
1709[*CommonJS entry points:*](#commonjs)
1710```js
1711core-js(/library)/fn/error/is-error
1712```
1713* `Math.{iaddh, isubh, imulh, umulh}` [proposal](https://gist.github.com/BrendanEich/4294d5c212a6d2254703) - modules [`es7.math.iaddh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.iaddh.js), [`es7.math.isubh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.isubh.js), [`es7.math.imulh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.imulh.js) and [`es7.math.umulh`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.math.umulh.js)
1714```js
1715Math
1716 .iaddh(lo0, hi0, lo1, hi1) -> int32
1717 .isubh(lo0, hi0, lo1, hi1) -> int32
1718 .imulh(a, b) -> int32
1719 .umulh(a, b) -> uint32
1720```
1721[*CommonJS entry points:*](#commonjs)
1722```js
1723core-js(/library)/fn/math/iaddh
1724core-js(/library)/fn/math/isubh
1725core-js(/library)/fn/math/imulh
1726core-js(/library)/fn/math/umulh
1727```
1728* `global.asap`, [TC39 discussion](https://github.com/rwaldron/tc39-notes/blob/master/es6/2014-09/sept-25.md#510-globalasap-for-enqueuing-a-microtask), module [`es7.asap`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.asap.js)
1729```js
1730asap(fn) -> void
1731```
1732[*CommonJS entry points:*](#commonjs)
1733```js
1734core-js(/library)/fn/asap
1735```
1736[*Examples*](http://goo.gl/tx3SRK):
1737```js
1738asap(() => console.log('called as microtask'));
1739```
1740
1741#### Pre-stage 0 proposals
1742[*CommonJS entry points:*](#commonjs)
1743```js
1744core-js(/library)/stage/pre
1745```
1746* `Reflect` metadata [proposal](https://github.com/jonathandturner/decorators/blob/master/specs/metadata.md) - modules [`es7.reflect.define-metadata`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.define-metadata.js), [`es7.reflect.delete-metadata`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.delete-metadata.js), [`es7.reflect.get-metadata`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.get-metadata.js), [`es7.reflect.get-metadata-keys`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.get-metadata-keys.js), [`es7.reflect.get-own-metadata`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.get-own-metadata.js), [`es7.reflect.get-own-metadata-keys`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.get-own-metadata-keys.js), [`es7.reflect.has-metadata`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.has-metadata.js), [`es7.reflect.has-own-metadata`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.has-own-metadata.js) and [`es7.reflect.metadata`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/es7.reflect.metadata.js).
1747```js
1748Reflect
1749 .defineMetadata(metadataKey, metadataValue, target, propertyKey?) -> void
1750 .getMetadata(metadataKey, target, propertyKey?) -> var
1751 .getOwnMetadata(metadataKey, target, propertyKey?) -> var
1752 .hasMetadata(metadataKey, target, propertyKey?) -> bool
1753 .hasOwnMetadata(metadataKey, target, propertyKey?) -> bool
1754 .deleteMetadata(metadataKey, target, propertyKey?) -> bool
1755 .getMetadataKeys(target, propertyKey?) -> array
1756 .getOwnMetadataKeys(target, propertyKey?) -> array
1757 .metadata(metadataKey, metadataValue) -> decorator(target, targetKey?) -> void
1758```
1759[*CommonJS entry points:*](#commonjs)
1760```js
1761core-js(/library)/fn/reflect/define-metadata
1762core-js(/library)/fn/reflect/delete-metadata
1763core-js(/library)/fn/reflect/get-metadata
1764core-js(/library)/fn/reflect/get-metadata-keys
1765core-js(/library)/fn/reflect/get-own-metadata
1766core-js(/library)/fn/reflect/get-own-metadata-keys
1767core-js(/library)/fn/reflect/has-metadata
1768core-js(/library)/fn/reflect/has-own-metadata
1769core-js(/library)/fn/reflect/metadata
1770```
1771[*Examples*](http://goo.gl/KCo3PS):
1772```js
1773var O = {};
1774Reflect.defineMetadata('foo', 'bar', O);
1775Reflect.ownKeys(O); // => []
1776Reflect.getOwnMetadataKeys(O); // => ['foo']
1777Reflect.getOwnMetadata('foo', O); // => 'bar'
1778```
1779
1780### Web standards
1781[*CommonJS entry points:*](#commonjs)
1782```js
1783core-js(/library)/web
1784```
1785#### setTimeout / setInterval
1786Module [`web.timers`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/web.timers.js). Additional arguments fix for IE9-.
1787```js
1788setTimeout(fn(...args), time, ...args) -> id
1789setInterval(fn(...args), time, ...args) -> id
1790```
1791[*CommonJS entry points:*](#commonjs)
1792```js
1793core-js(/library)/web/timers
1794core-js(/library)/fn/set-timeout
1795core-js(/library)/fn/set-interval
1796```
1797```js
1798// Before:
1799setTimeout(log.bind(null, 42), 1000);
1800// After:
1801setTimeout(log, 1000, 42);
1802```
1803#### setImmediate
1804Module [`web.immediate`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/web.immediate.js). [`setImmediate` proposal](https://developer.mozilla.org/en-US/docs/Web/API/Window.setImmediate) polyfill.
1805```js
1806setImmediate(fn(...args), ...args) -> id
1807clearImmediate(id) -> void
1808```
1809[*CommonJS entry points:*](#commonjs)
1810```js
1811core-js(/library)/web/immediate
1812core-js(/library)/fn/set-immediate
1813core-js(/library)/fn/clear-immediate
1814```
1815[*Examples*](http://goo.gl/6nXGrx):
1816```js
1817setImmediate(function(arg1, arg2){
1818 console.log(arg1, arg2); // => Message will be displayed with minimum delay
1819}, 'Message will be displayed', 'with minimum delay');
1820
1821clearImmediate(setImmediate(function(){
1822 console.log('Message will not be displayed');
1823}));
1824```
1825#### Iterable DOM collections
1826Some DOM collections should have [iterable interface](https://heycam.github.io/webidl/#idl-iterable) or should be [inherited from `Array`](https://heycam.github.io/webidl/#LegacyArrayClass). That mean they should have `keys`, `values`, `entries` and `@@iterator` methods for iteration. So add them. Module [`web.dom.iterable`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/web.dom.iterable.js):
1827```js
1828{
1829 CSSRuleList,
1830 CSSStyleDeclaration,
1831 CSSValueList,
1832 ClientRectList,
1833 DOMRectList,
1834 DOMStringList,
1835 DOMTokenList,
1836 DataTransferItemList,
1837 FileList,
1838 HTMLAllCollection,
1839 HTMLCollection,
1840 HTMLFormElement,
1841 HTMLSelectElement,
1842 MediaList,
1843 MimeTypeArray,
1844 NamedNodeMap,
1845 NodeList,
1846 PaintRequestList,
1847 Plugin,
1848 PluginArray,
1849 SVGLengthList,
1850 SVGNumberList,
1851 SVGPathSegList,
1852 SVGPointList,
1853 SVGStringList,
1854 SVGTransformList,
1855 SourceBufferList,
1856 StyleSheetList,
1857 TextTrackCueList,
1858 TextTrackList,
1859 TouchList
1860}
1861 #@@iterator() -> iterator (values)
1862
1863{
1864 DOMTokenList,
1865 NodeList
1866}
1867 #values() -> iterator
1868 #keys() -> iterator
1869 #entries() -> iterator
1870```
1871[*CommonJS entry points:*](#commonjs)
1872```js
1873core-js(/library)/web/dom-collections
1874core-js(/library)/fn/dom-collections/iterator
1875```
1876[*Examples*](http://goo.gl/lfXVFl):
1877```js
1878for(var {id} of document.querySelectorAll('*')){
1879 if(id)console.log(id);
1880}
1881
1882for(var [index, {id}] of document.querySelectorAll('*').entries()){
1883 if(id)console.log(index, id);
1884}
1885```
1886### Non-standard
1887[*CommonJS entry points:*](#commonjs)
1888```js
1889core-js(/library)/core
1890```
1891#### Object
1892Modules [`core.object.is-object`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.object.is-object.js), [`core.object.classof`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.object.classof.js), [`core.object.define`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.object.define.js), [`core.object.make`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.object.make.js).
1893```js
1894Object
1895 .isObject(var) -> bool
1896 .classof(var) -> string
1897 .define(target, mixin) -> target
1898 .make(proto | null, mixin?) -> object
1899```
1900
1901[*CommonJS entry points:*](#commonjs)
1902```js
1903core-js(/library)/core/object
1904core-js(/library)/fn/object/is-object
1905core-js(/library)/fn/object/define
1906core-js(/library)/fn/object/make
1907```
1908Object classify [*examples*](http://goo.gl/YZQmGo):
1909```js
1910Object.isObject({}); // => true
1911Object.isObject(isNaN); // => true
1912Object.isObject(null); // => false
1913
1914var classof = Object.classof;
1915
1916classof(null); // => 'Null'
1917classof(undefined); // => 'Undefined'
1918classof(1); // => 'Number'
1919classof(true); // => 'Boolean'
1920classof('string'); // => 'String'
1921classof(Symbol()); // => 'Symbol'
1922
1923classof(new Number(1)); // => 'Number'
1924classof(new Boolean(true)); // => 'Boolean'
1925classof(new String('string')); // => 'String'
1926
1927var fn = function(){}
1928 , list = (function(){return arguments})(1, 2, 3);
1929
1930classof({}); // => 'Object'
1931classof(fn); // => 'Function'
1932classof([]); // => 'Array'
1933classof(list); // => 'Arguments'
1934classof(/./); // => 'RegExp'
1935classof(new TypeError); // => 'Error'
1936
1937classof(new Set); // => 'Set'
1938classof(new Map); // => 'Map'
1939classof(new WeakSet); // => 'WeakSet'
1940classof(new WeakMap); // => 'WeakMap'
1941classof(new Promise(fn)); // => 'Promise'
1942
1943classof([].values()); // => 'Array Iterator'
1944classof(new Set().values()); // => 'Set Iterator'
1945classof(new Map().values()); // => 'Map Iterator'
1946
1947classof(Math); // => 'Math'
1948classof(JSON); // => 'JSON'
1949
1950function Example(){}
1951Example.prototype[Symbol.toStringTag] = 'Example';
1952
1953classof(new Example); // => 'Example'
1954```
1955`Object.define` and `Object.make` [*examples*](http://goo.gl/rtpD5Z):
1956```js
1957// Before:
1958Object.defineProperty(target, 'c', {
1959 enumerable: true,
1960 configurable: true,
1961 get: function(){
1962 return this.a + this.b;
1963 }
1964});
1965
1966// After:
1967Object.define(target, {
1968 get c(){
1969 return this.a + this.b;
1970 }
1971});
1972
1973// Shallow object cloning with prototype and descriptors:
1974var copy = Object.make(Object.getPrototypeOf(src), src);
1975
1976// Simple inheritance:
1977function Vector2D(x, y){
1978 this.x = x;
1979 this.y = y;
1980}
1981Object.define(Vector2D.prototype, {
1982 get xy(){
1983 return Math.hypot(this.x, this.y);
1984 }
1985});
1986function Vector3D(x, y, z){
1987 Vector2D.apply(this, arguments);
1988 this.z = z;
1989}
1990Vector3D.prototype = Object.make(Vector2D.prototype, {
1991 constructor: Vector3D,
1992 get xyz(){
1993 return Math.hypot(this.x, this.y, this.z);
1994 }
1995});
1996
1997var vector = new Vector3D(9, 12, 20);
1998console.log(vector.xy); // => 15
1999console.log(vector.xyz); // => 25
2000vector.y++;
2001console.log(vector.xy); // => 15.811388300841896
2002console.log(vector.xyz); // => 25.495097567963924
2003```
2004#### Dict
2005Module [`core.dict`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.dict.js). Based on [TC39 discuss](https://github.com/rwaldron/tc39-notes/blob/master/es6/2012-11/nov-29.md#collection-apis-review) / [strawman](http://wiki.ecmascript.org/doku.php?id=harmony:modules_standard#dictionaries).
2006```js
2007[new] Dict(iterable (entries) | object ?) -> dict
2008 .isDict(var) -> bool
2009 .values(object) -> iterator
2010 .keys(object) -> iterator
2011 .entries(object) -> iterator (entries)
2012 .has(object, key) -> bool
2013 .get(object, key) -> val
2014 .set(object, key, value) -> object
2015 .forEach(object, fn(val, key, @), that) -> void
2016 .map(object, fn(val, key, @), that) -> new @
2017 .mapPairs(object, fn(val, key, @), that) -> new @
2018 .filter(object, fn(val, key, @), that) -> new @
2019 .some(object, fn(val, key, @), that) -> bool
2020 .every(object, fn(val, key, @), that) -> bool
2021 .find(object, fn(val, key, @), that) -> val
2022 .findKey(object, fn(val, key, @), that) -> key
2023 .keyOf(object, var) -> key
2024 .includes(object, var) -> bool
2025 .reduce(object, fn(memo, val, key, @), memo?) -> var
2026```
2027
2028[*CommonJS entry points:*](#commonjs)
2029```js
2030core-js(/library)/core/dict
2031core-js(/library)/fn/dict
2032```
2033`Dict` create object without prototype from iterable or simple object.
2034
2035[*Examples*](http://goo.gl/pnp8Vr):
2036```js
2037var map = new Map([['a', 1], ['b', 2], ['c', 3]]);
2038
2039Dict(); // => {__proto__: null}
2040Dict({a: 1, b: 2, c: 3}); // => {__proto__: null, a: 1, b: 2, c: 3}
2041Dict(map); // => {__proto__: null, a: 1, b: 2, c: 3}
2042Dict([1, 2, 3].entries()); // => {__proto__: null, 0: 1, 1: 2, 2: 3}
2043
2044var dict = Dict({a: 42});
2045dict instanceof Object; // => false
2046dict.a; // => 42
2047dict.toString; // => undefined
2048'a' in dict; // => true
2049'hasOwnProperty' in dict; // => false
2050
2051Dict.isDict({}); // => false
2052Dict.isDict(Dict()); // => true
2053```
2054`Dict.keys`, `Dict.values` and `Dict.entries` returns iterators for objects.
2055
2056[*Examples*](http://goo.gl/xAvECH):
2057```js
2058var dict = {a: 1, b: 2, c: 3};
2059
2060for(var key of Dict.keys(dict))console.log(key); // => 'a', 'b', 'c'
2061
2062for(var val of Dict.values(dict))console.log(val); // => 1, 2, 3
2063
2064for(var [key, val] of Dict.entries(dict)){
2065 console.log(key); // => 'a', 'b', 'c'
2066 console.log(val); // => 1, 2, 3
2067}
2068
2069new Map(Dict.entries(dict)); // => Map {a: 1, b: 2, c: 3}
2070```
2071Basic dict operations for objects with prototype [*examples*](http://goo.gl/B28UnG):
2072```js
2073'q' in {q: 1}; // => true
2074'toString' in {}; // => true
2075
2076Dict.has({q: 1}, 'q'); // => true
2077Dict.has({}, 'toString'); // => false
2078
2079({q: 1})['q']; // => 1
2080({}).toString; // => function toString(){ [native code] }
2081
2082Dict.get({q: 1}, 'q'); // => 1
2083Dict.get({}, 'toString'); // => undefined
2084
2085var O = {};
2086O['q'] = 1;
2087O['q']; // => 1
2088O['__proto__'] = {w: 2};
2089O['__proto__']; // => {w: 2}
2090O['w']; // => 2
2091
2092var O = {};
2093Dict.set(O, 'q', 1);
2094O['q']; // => 1
2095Dict.set(O, '__proto__', {w: 2});
2096O['__proto__']; // => {w: 2}
2097O['w']; // => undefined
2098```
2099Other methods of `Dict` module are static equivalents of `Array.prototype` methods for dictionaries.
2100
2101[*Examples*](http://goo.gl/xFi1RH):
2102```js
2103var dict = {a: 1, b: 2, c: 3};
2104
2105Dict.forEach(dict, console.log, console);
2106// => 1, 'a', {a: 1, b: 2, c: 3}
2107// => 2, 'b', {a: 1, b: 2, c: 3}
2108// => 3, 'c', {a: 1, b: 2, c: 3}
2109
2110Dict.map(dict, function(it){
2111 return it * it;
2112}); // => {a: 1, b: 4, c: 9}
2113
2114Dict.mapPairs(dict, function(val, key){
2115 if(key != 'b')return [key + key, val * val];
2116}); // => {aa: 1, cc: 9}
2117
2118Dict.filter(dict, function(it){
2119 return it % 2;
2120}); // => {a: 1, c: 3}
2121
2122Dict.some(dict, function(it){
2123 return it === 2;
2124}); // => true
2125
2126Dict.every(dict, function(it){
2127 return it === 2;
2128}); // => false
2129
2130Dict.find(dict, function(it){
2131 return it > 2;
2132}); // => 3
2133Dict.find(dict, function(it){
2134 return it > 4;
2135}); // => undefined
2136
2137Dict.findKey(dict, function(it){
2138 return it > 2;
2139}); // => 'c'
2140Dict.findKey(dict, function(it){
2141 return it > 4;
2142}); // => undefined
2143
2144Dict.keyOf(dict, 2); // => 'b'
2145Dict.keyOf(dict, 4); // => undefined
2146
2147Dict.includes(dict, 2); // => true
2148Dict.includes(dict, 4); // => false
2149
2150Dict.reduce(dict, function(memo, it){
2151 return memo + it;
2152}); // => 6
2153Dict.reduce(dict, function(memo, it){
2154 return memo + it;
2155}, ''); // => '123'
2156```
2157#### Partial application
2158Module [`core.function.part`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.function.part.js).
2159```js
2160Function
2161 #part(...args | _) -> fn(...args)
2162```
2163
2164[*CommonJS entry points:*](#commonjs)
2165```js
2166core-js/core/function
2167core-js(/library)/fn/function/part
2168core-js(/library)/fn/function/virtual/part
2169core-js(/library)/fn/_
2170```
2171`Function#part` partial apply function without `this` binding. Uses global variable `_` (`core._` for builds without global namespace pollution) as placeholder and not conflict with `Underscore` / `LoDash`.
2172
2173[*Examples*](http://goo.gl/p9ZJ8K):
2174```js
2175var fn1 = log.part(1, 2);
2176fn1(3, 4); // => 1, 2, 3, 4
2177
2178var fn2 = log.part(_, 2, _, 4);
2179fn2(1, 3); // => 1, 2, 3, 4
2180
2181var fn3 = log.part(1, _, _, 4);
2182fn3(2, 3); // => 1, 2, 3, 4
2183
2184fn2(1, 3, 5); // => 1, 2, 3, 4, 5
2185fn2(1); // => 1, 2, undefined, 4
2186```
2187#### Number Iterator
2188Module [`core.number.iterator`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.number.iterator.js).
2189```js
2190Number
2191 #@@iterator() -> iterator
2192```
2193
2194[*CommonJS entry points:*](#commonjs)
2195```js
2196core-js(/library)/core/number
2197core-js(/library)/fn/number/iterator
2198core-js(/library)/fn/number/virtual/iterator
2199```
2200[*Examples*](http://goo.gl/o45pCN):
2201```js
2202for(var i of 3)console.log(i); // => 0, 1, 2
2203
2204[...10]; // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
2205
2206Array.from(10, Math.random); // => [0.9817775336559862, 0.02720663254149258, ...]
2207
2208Array.from(10, function(it){
2209 return this + it * it;
2210}, .42); // => [0.42, 1.42, 4.42, 9.42, 16.42, 25.42, 36.42, 49.42, 64.42, 81.42]
2211```
2212#### Escaping strings
2213Modules [`core.regexp.escape`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.regexp.escape.js), [`core.string.escape-html`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.string.escape-html.js) and [`core.string.unescape-html`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.string.unescape-html.js).
2214```js
2215RegExp
2216 .escape(str) -> str
2217String
2218 #escapeHTML() -> str
2219 #unescapeHTML() -> str
2220```
2221[*CommonJS entry points:*](#commonjs)
2222```js
2223core-js(/library)/core/regexp
2224core-js(/library)/core/string
2225core-js(/library)/fn/regexp/escape
2226core-js(/library)/fn/string/escape-html
2227core-js(/library)/fn/string/unescape-html
2228core-js(/library)/fn/string/virtual/escape-html
2229core-js(/library)/fn/string/virtual/unescape-html
2230```
2231[*Examples*](http://goo.gl/6bOvsQ):
2232```js
2233RegExp.escape('Hello, []{}()*+?.\\^$|!'); // => 'Hello, \[\]\{\}\(\)\*\+\?\.\\\^\$\|!'
2234
2235'<script>doSomething();</script>'.escapeHTML(); // => '&lt;script&gt;doSomething();&lt;/script&gt;'
2236'&lt;script&gt;doSomething();&lt;/script&gt;'.unescapeHTML(); // => '<script>doSomething();</script>'
2237```
2238#### delay
2239Module [`core.delay`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.delay.js). [Promise](#ecmascript-6-promise)-returning delay function, [esdiscuss](https://esdiscuss.org/topic/promise-returning-delay-function).
2240```js
2241delay(ms) -> promise
2242```
2243[*CommonJS entry points:*](#commonjs)
2244```js
2245core-js(/library)/core/delay
2246core-js(/library)/fn/delay
2247```
2248[*Examples*](http://goo.gl/lbucba):
2249```js
2250delay(1e3).then(() => console.log('after 1 sec'));
2251
2252(async () => {
2253 await delay(3e3);
2254 console.log('after 3 sec');
2255
2256 while(await delay(3e3))console.log('each 3 sec');
2257})();
2258```
2259#### Helpers for iterators
2260Modules [`core.is-iterable`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.is-iterable.js), [`core.get-iterator`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.get-iterator.js), [`core.get-iterator-method`](https://github.com/zloirock/core-js/blob/v2.6.10/modules/core.get-iterator-method.js) - helpers for check iterability / get iterator in the `library` version or, for example, for `arguments` object:
2261```js
2262core
2263 .isIterable(var) -> bool
2264 .getIterator(iterable) -> iterator
2265 .getIteratorMethod(var) -> function | undefined
2266```
2267[*CommonJS entry points:*](#commonjs)
2268```js
2269core-js(/library)/fn/is-iterable
2270core-js(/library)/fn/get-iterator
2271core-js(/library)/fn/get-iterator-method
2272```
2273[*Examples*](http://goo.gl/SXsM6D):
2274```js
2275var list = (function(){
2276 return arguments;
2277})(1, 2, 3);
2278
2279console.log(core.isIterable(list)); // true;
2280
2281var iter = core.getIterator(list);
2282console.log(iter.next().value); // 1
2283console.log(iter.next().value); // 2
2284console.log(iter.next().value); // 3
2285console.log(iter.next().value); // undefined
2286
2287core.getIterator({}); // TypeError: [object Object] is not iterable!
2288
2289var iterFn = core.getIteratorMethod(list);
2290console.log(typeof iterFn); // 'function'
2291var iter = iterFn.call(list);
2292console.log(iter.next().value); // 1
2293console.log(iter.next().value); // 2
2294console.log(iter.next().value); // 3
2295console.log(iter.next().value); // undefined
2296
2297console.log(core.getIteratorMethod({})); // undefined
2298```
2299
2300## Missing polyfills
2301- ES5 `JSON` is missing now only in IE7- and never will it be added to `core-js`, if you need it in these old browsers, many implementations are available, for example, [json3](https://github.com/bestiejs/json3).
2302- ES6 `String#normalize` is not a very useful feature, but this polyfill will be very large. If you need it, you can use [unorm](https://github.com/walling/unorm/).
2303- ES6 `Proxy` can't be polyfilled, but for Node.js / Chromium with additional flags you can try [harmony-reflect](https://github.com/tvcutsem/harmony-reflect) for adapt old style `Proxy` API to final ES6 version.
2304- ES6 logic for `@@isConcatSpreadable` and `@@species` (in most places) can be polyfilled without problems, but it will cause a serious slowdown in popular cases in some engines. It will be polyfilled when it will be implemented in modern engines.
2305- ES7 `SIMD`. `core-js` doesn't add polyfill of this feature because of large size and some other reasons. You can use [this polyfill](https://github.com/tc39/ecmascript_simd/blob/master/src/ecmascript_simd.js).
2306- `window.fetch` is not a cross-platform feature, in some environments it makes no sense. For this reason, I don't think it should be in `core-js`. Looking at a large number of requests it *may be* added in the future. Now you can use, for example, [this polyfill](https://github.com/github/fetch).
2307- ECMA-402 `Intl` is missed because of size. You can use [this polyfill](https://github.com/andyearnshaw/Intl.js/).