![javascript](https://habrastorage.org/r/w120/webt/59/cc/76/59cc7600c78a2239379574.jpeg)
JavaScript
5
Вклад в тег
// tracked variable
let num = 1;
// add an observer, pass the name and function that returns the variable
trackChanges.addObserver('numObserv', () => num);
// add a handler, pass the name and function that will be called when changing "num"
trackChanges.addHandler('numObserv', numHandler);
/**
create a function that will be called when the variable changes, the function argument will be its changed value
**/
function numHandler(modifiedResult) {
console.log(`Num changed to: ${ modifiedResult }`);
}