main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
757 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var aMap = require('../internals/a-map');
|
---|
4 | var MapHelpers = require('../internals/map-helpers');
|
---|
5 |
|
---|
6 | var get = MapHelpers.get;
|
---|
7 | var has = MapHelpers.has;
|
---|
8 | var set = MapHelpers.set;
|
---|
9 |
|
---|
10 | // `Map.prototype.emplace` method
|
---|
11 | // https://github.com/tc39/proposal-upsert
|
---|
12 | $({ target: 'Map', proto: true, real: true, forced: true }, {
|
---|
13 | emplace: function emplace(key, handler) {
|
---|
14 | var map = aMap(this);
|
---|
15 | var value, inserted;
|
---|
16 | if (has(map, key)) {
|
---|
17 | value = get(map, key);
|
---|
18 | if ('update' in handler) {
|
---|
19 | value = handler.update(value, key, map);
|
---|
20 | set(map, key, value);
|
---|
21 | } return value;
|
---|
22 | }
|
---|
23 | inserted = handler.insert(key, map);
|
---|
24 | set(map, key, inserted);
|
---|
25 | return inserted;
|
---|
26 | }
|
---|
27 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.