3

I'm looking for a higher-level language that writes out javascript. in other words the relation of this language to javascript is similar to the relation C++ have with assembly code.

The requirements of this higher-level language is type-safety, easy refactoring, able to have classes, inheritance etc (abit like java/C#/vb.net).

The advantage is that I can code at this higher level language without having to rely on "hacks" to bring inheritance over to javascript. Moreover i do not have to do any runtime type/duck checks since the higher level language will impose the type-safety limit and the generated javascript will just "do the job".

Additional advantages would be any of the advantages we could have when we code in C++ compared to coding in assembly.

I'm actually going to try and write this higher-level language myself but its too much work and I was wondering if anyone had actually already did something like it.

asked May 13, 2011 at 10:52
3
  • Many people have implemented languages on top of JavaScript, such as CoffeeScript and ParenScript. Are you looking for something with inheritance specifically? Commented May 13, 2011 at 10:53
  • 2
    Take a look at Google Web Toolkit: code.google.com/webtoolkit Commented May 13, 2011 at 10:55
  • @Greg Hewgill yes that's one of my requirements Commented May 13, 2011 at 15:41

4 Answers 4

4

CoffeeScript.

CoffeeScripts aim is not to have an already existing high level language compile down to JavaScript but to create a new language as a "Better JavaScript than JavaScript".

This is similar to using C++ as a "better C than C".

Of course since it's closer to JavaScript it fully supports all JavaScript features. The compiler is also written in CoffeeScript (JavaScript) itself.

Greg Hewgill
1.0m193 gold badges1.2k silver badges1.3k bronze badges
answered May 13, 2011 at 14:43
Sign up to request clarification or add additional context in comments.

5 Comments

btw CoffeeScript does not have support for inheritance right?
@Raynos heys coffeescript looks cool but i've got 2 questions. Firstly is there a way to turn on "type-safety" option (compile-time type safety checks instead of runtime type-safety checks), also is there an IDE for it? (otherwise it wouldn't allow easy refactoring)
@Pacerier "Is there an IDE". JavaScript has ide's. WebStorm / Netbeans / VIM. CoffeeScript is not strictly typed because JavaScript is not. Personally I think this is a good thing. You don't want types. CoffeeScript is supposed to mirror python
@Raynos however without types we could not enforce intellisense and compile-time checks.
@Pacerier JavaScript does not need those. Intellisense is not needed, and strict typing severely limits the power of JavaScript. Your trying to put JavaScript into a box where it does not fit. Try using it as JavaScript.
2

There's Script#, which compiles C# code into JavaScript. Not sure about any limitations it might have, though. There's also jsc, which converts a .NET assembly to JavaScript through decompilation.

Neither, AFK, compile to make use of the new features in ECMAScript 5th edition.

answered May 13, 2011 at 10:56

3 Comments

I've used Script#. The only thing that keeps me using it instead of gwt is that I don't want to add an additional language dependency to my projects (Java). If you have no such constraints, then gwt is definitely the more mature product.
@Pacerier: Not to my knowledge. There's just JSC which would convert a .NET assembly made in VB.NET.
@Charlie Kilian dang Script# does not support inheritance!
2

Google Web Toolkit (GWT) Java code to JavaScript as parter of a broader scope. Here's a snippet from the adjacent link:

The GWT SDK provides a set of core Java APIs and Widgets. These allow you to write AJAX applications in Java and then compile the source to highly optimized JavaScript that runs across all browsers, including mobile browsers for Android and the iPhone.

You can, of course compile JavaScript from JavaScript itself with the Google Closure Compiler.

Also checkout this Scott Mitchell's blog article regarding Script#

But, as @Andy E states - nothing claiming to work for ECMAScript5

Levi Morrison
19.6k8 gold badges69 silver badges87 bronze badges
answered May 13, 2011 at 10:56

2 Comments

That was Scott Mitchell's article, not mine. (Scott has a link to some of my articles later on, but they are on different topics; I've never written on Script#.)
heys I've looked abit at the GWT api anyway does GWT actually allows us to create our own classes from scratch instead of using their API? (i'm actually totally not interested in their APIs, what i need is a language to language converter)
1

You should consider having a look at LLVM in combination with emscripten. It will allow you to compile a great deal of languages (including C and C++) into LLVM bitcode and then to JavaScript. This is from their projects page:

Emscripten compiles LLVM bitcode into JavaScript, which makes it possible to compile C and C++ source code to JavaScript (by first compiling it into LLVM bitcode using Clang), which can be run on the web. Emscripten has been used to port large existing C and C++ codebases, for example Python (the standard CPython implementation), the Bullet physics engine, and the eSpeak speech synthesizer, among many others.

One particularly amazing port using this technique is the box2d.js project, which takes the great box2d library and turns it into this amazing demo.

answered Oct 18, 2012 at 14:33

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.