|
|
|
|
|
by nnq
4724 days ago
|
|
Ah, destructuring is so sweet! You're right, it's no real need for it and it's unfeasible because you need to either (a) fully static type analyze everything or (b) what anonymous just explained... and they're both out of the question. The refinements thing was a joke, in the spirit of what else can one add: it's a controlled form of monkeypatching / classboxing about which a lot of fuss was made in the Ruby community after Matz decided to add it to the language (http://timelessrepo.com/refinements-in-ruby), mainly because it's very hard to implement without creating more problems, even if you have your own interpreter to hack on (short answer: don't bother looking about it and even if you're smart enough to figure out a way to add it to a compile-to-JS language, don't waste your effort on it - they're not an anti-feature and they could make sense in languages that allow monkeypatching, like JS and Ruby, but they're too much work for too little benefit and too much possibility for bad use and unneeded complexity). |
|
Also nice is that it doesn't have to create a full defaults object at runtime, and each binding would only be evaluated if individually needed:
You can do all sorts of things with object destructuring.Yeah, Refinements seem like a similar thing to extension classes in .NET where methods defined somewhere else affect a class but only if included, without polluting the globals.
The only possible way I could see supporting something like this is with a different method call operator, so something like:
NOTE: The following is theoretical code. It does not work in GorillaScript 0.9.x, but might be implemented if there is enough positive feedback for it.
Also, refinements could have macros on them, so one could do So, this would be a nice way to have refinements, but have the terrible downside of requiring the type to be statically known.You could also define a refinement on a union type or even an object type, such as the following:
The refinement namespace would not conflict with the normal invocation namespace, so you could have `"Hello".same()` and have it be exactly as expected, but `"Hello"->same()` not, because it would turn into `String_$_same("Hello")` (or something like it).To clarify before, the following would work:
I dunno, something to think about. Would people want to have this feature?