Javascript 代理设置一个值
Javascript 代理设置一个值,javascript,Javascript,var context={}; 让头; context.head=新代理({}{ 获取(对象、道具){ 如果(!头){ 头={ htmlAttrs:{ 朗:“Fr” } } } 如果(prop=='htmlAttrs'){ 返回`${JSON.stringify(head.htmlAttrs)}` } }, 设置(对象、道具、值、记录){ 返回Reflect.set(…参数); } }) context.head.htmlAttrs={ 关键:对 } console.log(context.he
var context={};
让头;
context.head=新代理({}{
获取(对象、道具){
如果(!头){
头={
htmlAttrs:{
朗:“Fr”
}
}
}
如果(prop=='htmlAttrs'){
返回`${JSON.stringify(head.htmlAttrs)}`
}
},
设置(对象、道具、值、记录){
返回Reflect.set(…参数);
}
})
context.head.htmlAttrs={
关键:对
}
console.log(context.head.htmlAttrs)
在本例中,get()
返回的obj
变量包含:
var context={};
让头;
context.head=新代理({}{
获取(对象、道具){
如果(!头){
头={
htmlAttrs:{
//包括属性
…obj.htmlAttrs,
朗:“Fr”
}
}
}
如果(prop=='htmlAttrs'){
返回`${JSON.stringify(head.htmlAttrs)}`
}
const text=head中的prop?head[prop]。text():“”
返回文本(&prop.endsWith('Attrs')?`${text}`:text
},
设置(对象、道具、值、记录){
返回Reflect.set(…参数);
}
})
context.head.htmlAttrs={
关键:对
}
console.log(context.head.htmlAttrs)
你到底想做什么?我是@hackape的,你想做什么?