its rough and ready, but here is something that sort of works
var mod=newproxy();
mod.callme.first$('hello','world'); //? mod.callme.first.fn('hello','world');
mod.difcontext.hello='world'; //? mod.difcontext.hello.prop='world';
mod.difcontext.start=['hello','world'];
mod.difcontext.cat_; //? mod.difcontext.cat.prop;
function newproxy(main){
main=main||{};
return proxy(main);
function getter(target,name,receiver,lname){
lname+=lname?'.'+name:name;
var c=name[name.length-1];
if(c==='$'){
lname=lname.slice(0,-1);
return function(){
console.log('fn : ',lname,arguments);
};
}
if(c==='_'){
lname=lname.slice(0,-1);
console.log('rd : ',lname);
return;
}
return proxy(target,lname);
}//getter
function setter(obj,prop,newval,lname){
lname+=lname?'.'+prop:prop;
console.log('wt : ',lname,newval);
}//setter
function proxy(target,lname){
lname=lname||'';
var p=new Proxy(target,{
get:(target,name,receiver)=>{return getter(target,name,receiver,lname);},
set:(obj,prop,newval)=>{return setter(obj,prop,newval,lname);}
});
return p;
}//proxy
}//newproxy
uses a naming convention
$ denotes an ending function, ( could of ended with .fn )
_ denotes reading variable, ( could of ended with .prop )
the setter could be used to invoke a function, but its not conventional
for the time being i decided to go with
mod('difcontext.callme.first',['hello','world'],callback);
if the getters intrinsically had some knowledge of how they were being invoked ...
var mod=new Proxy({},{
get:(target,name,receiver)=>{return function(){alert(name)}}
});
mod.hello();
I was referred to another question, i posted a more complete solution there :
Is there an equivalent of the noSuchMethod feature for properties, or a way to implement it in JS?