[JavaScript] 纯文本查看 复制代码
const person = {
name: 'zs',
age: 18,
};
const personProxy = new Proxy(person, {
get() {},
set() {},
});
[JavaScript] 纯文本查看 复制代码
{
get(target, property) {
console.log(target, property);
return property in target ? target[property] : undefined;
}
}
[JavaScript] 纯文本查看 复制代码
{
set(target, property, value) {
console.log(target, property, value);
if (property === 'age') {
if (!Number.isInteger(value)) {
throw new TypeError('${value} must be a integer');
}
}
target[property] = value;
}
}