Относительно тривиально наблюдать за изменениями в массиве в Javascript.
Один из методов, который я использую, выглядит так:
// subscribe to add, update, delete, and splice changes
Array.observe(viewHelpFiles, function(changes) {
// handle changes... in this case, we'll just log them
changes.forEach(function(change) {
console.log(Object.keys(change).reduce(function(p, c) {
if (c !== "object" && c in change) {
p.push(c + ": " + JSON.stringify(change[c]));
}
return p;
}, []).join(", "));
});
});
Однако, я недавно прочитал, что Array.observe
устарел, и мы должны использовать прокси-объект .
Как мы можем обнаружить изменения в массиве объекта Proxy? Я не могу найти каких-либо примеров, кого интересует разработка?