项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

README.md 95 KiB

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