Answer the question
In order to leave comments, you need to log in
Proxying nested object changes in JavaScript?
Good day, %username%!
So JavaScript. We have an object (with load/save methods) to store application settings (in localstorage), and this object looks like this:
var SettingsStorage = {
data: {
some_value1: null,
child_object: {
some_value2: true,
some_value3: 1000
},
some_value4: null
},
load: function(callback) {
// load this.data from localstorage
},
save: function(callback) {
// save this.data to localstorage
}
};
var Settings = new Proxy(SettingsStorage.data, {
set: function(obj, prop, value) {
var storage_data = SettingsStorage.data;
if (obj === storage_data && prop === 'some_value1') {
console.log('Да да! Мы поймали момент изменения SettingsStorage.data.some_value1!');
}
obj[prop] = value;
return true;
}
});
Answer the question
In order to leave comments, you need to log in
https://jsfiddle.net/g1kebLbg Everything is very complicated. It took 2 hours and I'm still not sure that there are no bugs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question