@domenic that’s if a object has a method. For example:
var proxy = new Proxy({
m() { console.log('this is called'); }
}, {
get(target, prop) {
if(target[prop].constructor == Function) {
console.log('it's a function');
return target[prop];
}
}
});
proxy.m; // would log it's a function and return the method
proxy.m(); // .m returns it so () calls it logging "this is called"
Now with a proxied nodeList I want to be able to just trap method calls that are not a part of the nodeList (I’ll use an array literal here)
var p = new Proxy([document.body], {
get(target, prop) {
if(!target[prop]) {
return function() { console.log("it's called"); };
}
}
});
p.m(); // logs it's called;
p.whatever(); // logs it's called
Ok this works because Im checking if property doesn’t exist yet I’ll be doing that for everything else as well. Like getting textContent it will return an array of textContent for each node which is not a property of the NodeList.
I could just loop through each node and check if it’s a property or a method of each node, but that would be complicated because what if I query every element and try calling submit I’d have to do something really complicated and confusing? that in the long run would most likely be bad. So perhaps a proposal on function call traps? or is there already a discussion?
I could also just check HTMLElement.prototype[prop]
to see if it’s a method or property but then again with certain elements they have their own methods and properties.
Proxies would be easier, but I think manually implementing every method and property would be most beneficial.