Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
815 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var IS_PURE = require('../internals/is-pure');
|
---|
4 | var anObject = require('../internals/an-object');
|
---|
5 | var aFunction = require('../internals/a-function');
|
---|
6 |
|
---|
7 | // `Set.prototype.update` method
|
---|
8 | // https://github.com/tc39/proposal-collection-methods
|
---|
9 | $({ target: 'Map', proto: true, real: true, forced: IS_PURE }, {
|
---|
10 | update: function update(key, callback /* , thunk */) {
|
---|
11 | var map = anObject(this);
|
---|
12 | var length = arguments.length;
|
---|
13 | aFunction(callback);
|
---|
14 | var isPresentInMap = map.has(key);
|
---|
15 | if (!isPresentInMap && length < 3) {
|
---|
16 | throw TypeError('Updating absent value');
|
---|
17 | }
|
---|
18 | var value = isPresentInMap ? map.get(key) : aFunction(length > 2 ? arguments[2] : undefined)(key, map);
|
---|
19 | map.set(key, callback(value, key, map));
|
---|
20 | return map;
|
---|
21 | }
|
---|
22 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.