3 ms·
Has anyone tried running the solution? It doesn't seem to work... The below code results in the console logging the document object, which has the document o
by jasonmcaffee 7y ago
Has anyone tried running the solution? It doesn't seem to work...
The below code results in the console logging the document object, which has the document object, and the code hits a ReferenceError when trying to log the 'a' variable.
Calls to p.whateverPropYouMakeUp result in the log 'get for target: ...'
const proxyHandler = {
get(target, name){
console.log(`get for target: `, target, name);
return 'tacos';
},
}
const p = new Proxy({}, proxyHandler);
with (p){
console.log(`document with proxy: `, document);
console.log(`access random property: `, a);
}
https://jsfiddle.net/wf02n4gs/ https://jsfiddle.net/wf02n4gs/
- pfraze 7y agoI was able to make it work by adding a has() trap. https://jsfiddle.net/wepmLrh0/ https://jsfiddle.net/wepmLrh0/
- quickthrower2 7y agoThanks - I extended that to show two "widgets" being fed 2 different JQueries: https://jsfiddle.net/habla/a56807ng/ https://jsfiddle.net/habla/a56807ng/
- jasonmcaffee 7y agoAwesome! Thanks!