An accretion is an extensible object used an an alternative to this
, class
,
and new
.
const {create} = require('accretion');
const a = create({
foo: 'default value'
});
// b shallow copies a and overrides properties
const b = a.extend({
foo: 'overriding value',
bar: 'new property'
});
// c shallow copies b, and lets b override provided values.
const c = b.spread({
foo: 'new default value'
});
delete b.foo;
const d = b.spread({
foo: 'new default value if property is not already specified'
});
// {foo: 'default value', spread: [Function], extend: [Function] }
console.log(a);
// {foo: 'overriding value', bar: 'new property', spread, extend }
console.log(b);
// {foo: 'overriding value', bar: 'new property', spread, extend }
console.log(c);
// {foo: 'new default value', bar: 'new property', spread, extend }
console.log(d);