Skip to content

Instantly share code, notes, and snippets.

@RinatMullayanov
Created September 3, 2015 06:49
Show Gist options
  • Save RinatMullayanov/c032e1c357c0b0b2c022 to your computer and use it in GitHub Desktop.
Save RinatMullayanov/c032e1c357c0b0b2c022 to your computer and use it in GitHub Desktop.
ES 2015 Proxy sample based on http://learn.javascript.ru/proxy
(function () {
'use strict';
let user = {};
let proxy = new Proxy(user, {
get(target, prop) {
console.log(`Чтение ${prop}`);
return target[prop];
},
set(target, prop, value) {
console.log(`Запись ${prop} ${value}`);
target[prop] = value;
return true;
}
});
proxy.firstName = "Ilya"; // write
proxy.firstName; // read
console.log(user.firstName); // Ilya
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment