bind-late 
Late binding of overridable object properties.
Description
Define an overridable object where special "late binded" functions will
be treated as lazy memoized properties.
All the functions in the object structure that are anonymous and take a
single _
argument, are considered to be "late bindings". When the
property is accessed the first time, they are called with the final
overridden object as _
parameter, and their return value is affected
to the property.
Nesting
You can nest late binded objects. Late binded objects are not plain
objects and will not be recursively extended during an override
, so
you need to extend them explicitely (this is often what you want,
since override
would otherwise just copy your properties and not
rebuild the inner late binded object according to what you changed).
Example
const bindLate = require('bind-late')
const a = bindLate({
a: 8,
b: {
c: 2,
d: _ => _.a + _.b.c,
},
e: _ => _.b.d * 2,
})
a.b.d === 10
a.e === 20
const b = a.override({ a: 6 })
b.b.d === 8
b.e === 16
const c = b.override({
b: { c: 6 },
e: _ => _.b.d - 2,
})
c.b.d === 12
c.e === 10
You can also watch the antisocial-auth source code for a more
concrete example, where everything is overridable thanks to bind-late.
Demo
See the demo directory to see a functional example you can tweak
and play with.