Skip to content

Instantly share code, notes, and snippets.

@wdiasvargas
Created April 29, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdiasvargas/0824832f372515c163cbee556bae31c2 to your computer and use it in GitHub Desktop.
Save wdiasvargas/0824832f372515c163cbee556bae31c2 to your computer and use it in GitHub Desktop.
proxy ES6 with babel
/**
* Created by William Dias on 29/04/17.
* www.williamdiasvargas.com.br
*/
'use strict'
class Usuario {
constructor (login, senha) {
this.login = login;
this.senha = senha;
}
}
const proxy = new Proxy(usuario, {
get(alvo, propriedade) {
console.log(`${propriedade} foi solicitada`);
return alvo[propriedade];
}
});
console.log(proxy.login);
console.log(proxy.senha);
const usuario = new Usuario('SuperJS', '123');
console.log(usuario.login); //SuperJS
console.log(usuario.senha);//123
@wdiasvargas
Copy link
Author

executo o babel-node e essa é uma parte da saida pelo terminal

var proxy = new Proxy(usuario, {
^

TypeError: Cannot create proxy with a non-object as target or handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment