|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
922 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 | var $ = require('../internals/export');
|
|---|
| 3 | var aCallable = require('../internals/a-callable');
|
|---|
| 4 | var aMap = require('../internals/a-map');
|
|---|
| 5 | var MapHelpers = require('../internals/map-helpers');
|
|---|
| 6 |
|
|---|
| 7 | var $TypeError = TypeError;
|
|---|
| 8 | var get = MapHelpers.get;
|
|---|
| 9 | var has = MapHelpers.has;
|
|---|
| 10 | var set = MapHelpers.set;
|
|---|
| 11 |
|
|---|
| 12 | // `Map.prototype.update` method
|
|---|
| 13 | // https://github.com/tc39/proposal-collection-methods
|
|---|
| 14 | $({ target: 'Map', proto: true, real: true, forced: true }, {
|
|---|
| 15 | update: function update(key, callback /* , thunk */) {
|
|---|
| 16 | var map = aMap(this);
|
|---|
| 17 | var length = arguments.length;
|
|---|
| 18 | aCallable(callback);
|
|---|
| 19 | var isPresentInMap = has(map, key);
|
|---|
| 20 | if (!isPresentInMap && length < 3) {
|
|---|
| 21 | throw new $TypeError('Updating absent value');
|
|---|
| 22 | }
|
|---|
| 23 | var value = isPresentInMap ? get(map, key) : aCallable(length > 2 ? arguments[2] : undefined)(key, map);
|
|---|
| 24 | set(map, key, callback(value, key, map));
|
|---|
| 25 | return map;
|
|---|
| 26 | }
|
|---|
| 27 | });
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.