* Adds a key-value pair to the object. Throws an exception if the key is * already in use. Use set if you want to change an existing pair. * @param {?Object } obj The object to which to add the key-value pair. * @param {string} key The key to add. * @param {V} val The value to add. * @retur
(obj, key, val)
| 333 | * @template K,V |
| 334 | */ |
| 335 | function add(obj, key, val) { |
| 336 | if (obj !== null && key in obj) { |
| 337 | throw new Error(`The object already contains the key "${key}"`); |
| 338 | } |
| 339 | set(obj, key, val); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Returns the value for the given key. |