Your code example is already valid JavaScript, what it does can’t be changed.
the this inside a static method called like that will be a reference to the class constructor itself. So it can’t be used to call instance methods such as query, there should be an instance of the class
it is not clear what the problem is you are trying to solve, could you go into more detail?
Hi @aclaymore, thanks for the welcome. I've made some changes in the code to really show what the trouble we getting in without the proper abstraction of the class methods.
I guess now will be enought and quite clear to remember what we dealing at without the right abstraction of the methods.
btw - your proposal link seems to be broken (it gives me a 404 error).
Could you expound on why you're expecting the last line to log out "TWO"? The modified code example already runs without errors, and won't log anything out, because this.c() never gets called. (The return this || this.c(); lines cause this to simply be returned, since this is truthy). Are you wanting the return this || this.c(); lines to behave differently? If so, how and why?
A challenge here is that while it may look clear what should happen when we look at the code. There needs to be clear semantics for how this would work, and right now there is no mechanism for functions to change their behavior based on the 'position' of where they were called. The operation is apply and that does not pass any information other than the receiver and arguments. So:
Functions can’t, by design, behave differently based on where they’re called, except for the receiver. Making a function that works differently in a chain then not is imo a nonstarter.
This is an interesting problem space. I don't know if we'll be able to find any great solutions for it, but I'll at least like to take a step in, what I presume to be, a more acceptable direction.
For a syntax like this to be work-able, I think we'd need some sort of syntactic token to state that a chain is starting.