immutable objects

by Artem

JavaScript

'use strict';

Object.prototype.set = function(key, value) {
	return this[key] === value ? this : Object.assign({}, this, {key: value});
};

const a = {
	value: 1
};

const b = a.set('value', 1);
console.log(a === b);