Replies: 1 comment
-
There was such a project called SugarJS. Don't think it's maintained anymore though. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For personal projects I use altered version of JS/TS, modifying the built-in prototypes. Here's one-page of all the addition https://gist.github.com/al6x/96443c3cdda1de0b039d6f70abfdb09c
The effect - it feels as if you write Ruby instead of JS. I like it and use in personal projects when I control the JS environment. The problem of course, the large scale development with such approach is not possible.
There's a way to make it safe, the well known Extension Methods as in Kotlin, Nim etc. It's possible to implement it in TypeScript, as compiler knows the types most of the time and can replace
v.abs()
withnumber_abs(v)
, but the official position of TS team is that they reject anything that's not Standard JS Feature.P.S.
There's also a hacky way to do something like that, you replace every method call in Civet file as
v.abs()
asv.abs_()
. You also would need to alter built-in prototypes withxxx_
methods, but it's easy, also along the way it's possible to fix JS bugs like providing a propersort_
implementation. Or, just dropping the whole JS standard library (which is not good in my opinion), and providing a much better, Ruby-like methods on built-in objects.Basically, you get Ruby like lang (or whatever you like), with types and JS runtime :)
The limitation - it's a bit dirty and conflicts still possible, and when using other libraries you need to write code as
some_obj.call_()
so Civet would replace it backward intosome_obj.call()
.I did this with JS AST transformers, it's actually works quite well, but no types, and Civet can do this with types.
Beta Was this translation helpful? Give feedback.
All reactions