adelriosantiago
adelriosantiago

Reputation: 8134

How to watch for variable changes at all levels in NodeJS

I have this variable in NodeJS:

var toWatch = {
    count: 3,
    name: {
        first: "Foo",
        last: "Bar"
    }
}

And I want to fire a function when any value of it changes. For example, toWatch.name.first = "ABC" and toWatch.newProperty = 123 would both trigger this function.

How can I implement this function?

Upvotes: 1

Views: 3306

Answers (1)

guest271314
guest271314

Reputation: 1

You can use Proxy to observe set and get at a JavaScript object.

Upvotes: 0

Related Questions