smart-observe demo: compute
by longhao he
HTML
<script src="https://unpkg.com/smart-observe/dist/smart-observe.min.js"></script>
JavaScript
/* https://github.com/cnlon/smart-observe */
const target = {a: 1}
observe.compute(target, 'b', function () {
return this.a * 2
})
print(target.b)
// 2
target.a = 3
print(target.b)
// 6
function print(...args) {
const content = args.join(' ') + '<br>'
document.body.innerHTML += content
}