Created
September 3, 2015 06:49
-
-
Save RinatMullayanov/c032e1c357c0b0b2c022 to your computer and use it in GitHub Desktop.
ES 2015 Proxy sample based on http://learn.javascript.ru/proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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