Rather than overloading existing operators, might it be an idea to introduce
a new generic "programmable" operator? It's just a thought. In all fairness
it doesn't feel quite like js to me, but the desire to handle/define
operators seems to be present. Maybe the @ sign would be fitting for this.
It's already used in the spec to explain compound assignments. And it's big
enough such that you won't easily mistake it for something else.
var r = x @ y;
Now, of course people will want to program multiple operators. So maybe
something like
x @name@ y
would be better suited, where name may be pretty much anything except the at
sign itself.
The programmable operator would probably be a binary function.
function @+@(x,y){ return x+y; }
or
function @+@{ return x+y; }
(if/since it'd always be binary)
But one might think of constructs where you can define unary prefix/postfix
operators.
Again, I'm not convinced this is the way to go myself, just throwing it out
here. The whole proxy overloading thing just seems to "hide" what's actually
going on and overly complicate things. In production, that's gonna haunt you
some day.
- peter
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss