I want to be able to do this:
x.where('age').gt(20);
x.__calls // [['age', []], ['gt', [20]]]
where
and gt
are just examples. I do not know what functions will be called, they might be anything, and they don't do anything apart from filling the __calls
array.
So far I have the following code which uses ES6's Proxy object
var x = new Proxy({
__calls: []
}, {
get: function (target, name) {
if (name in target) {
return target[name];
} else {
return () => {
target.__calls.push([name, Array.prototype.slice.call(arguments)]);
return x;
}
}
}
});
If I remove the return x
line, I can do x.where('age'); x.gt(20)
to get the correct __calls
. However, with the return x
, it goes into infinite recursion for some reason...