function validator(target, validator) { return new Proxy(target, { _validator: validator, set(target, key, value, proxy){ if(target.hasOwnProperty[key]){ let va = this._validator[key]; if(!!va(value)){ return Reflect.set(target,key, value, proxy); } else { throw Error(`不能设置${key}到${value}`); } } else { throw Error(`${key} 不存在`) } } }) }
这里 set(target, key, value, proxy),不可以写成set(target, key, value)吗?这里的proxy有什么用?