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 }`);
}