/ javascript

ES6 的proxy

//设置的属性必须是 userName password loginType
```
var loginInfo = {
    userName: "",
    password: "",
    loginType: ""
};

function loginAction(loginInfo) {
    //进行登录
}

var loginInfoProxyHandler = {
    get: function (target, key, receiver) {
        if (key === "password") {
            return "*** ***";
        } else {
            return target[key];
        }
    },
    set: function (target, key, value, receiver) {
        if (Reflect.has(target, key)) {
            target[key] = value;
        } else {
            throw new Error('不需要设置:' + key);
        }
    }
};
var loginInfoProxy = new Proxy(loginInfo, loginInfoProxyHandler);


//要对代理操作,否则无效
loginInfoProxy.userName = "tom";//ok
loginInfoProxy.useName = "jane";//err 不需要设置:useName
loginInfoProxy.password;// *** ***
loginInfoProxy.userName;// tom
```