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