Proxies and Dynamic Methods
const spec = {
get(o, key) {
console.log(key, ':: key');
return o[key] != null ?
o[key] : o[key] = () => {
document.body.innerHTML += `<div>${key}!</div>`;
return anyMethod();
}
},
set(o, key, v) {
o[key] = v;
}
};
const anyMethod = () => new Proxy({}, spec);
anyMethod().now()
.this().is()
.pretty()
.cool()
.confusing()
.evil()?.or()
.maybe().powerful()
['... what <b>do</b> <i>you</i><br>']()
.think();
Proxies can be used for all manner of strange “magic”. I can actually see some uses for this, might post in the next few days…