When Rich Hickey announced ClojureScript he said "Why are we doing this? Because Clojure rocks, and JavaScript reaches." The simplest reason is because JS is the Language of the Web.
It's worth wondering why this is, and I don't really have an answer. In JS's infancy, Java was meant to be the Language of the Web and JS was its asthmatic younger brother. There are probably purely aesthetic problems which led to Java being overtaken by Flash, but I don't know. I sometimes like to say that Java looked consistent in every browser -- but consistently ugly. But Java is not necessarily fun to develop in either, and getting people to install Java always seemed like it was more pain than getting them to install the Flash plugin.
You can treat it as a black box, of course: even to this day, for lots of people, Java on the web just plain doesn't work. But I think you're asking why it doesn't work, and that's much more subtle. You know who would be an interesting person to ask? An advertiser. You see flash ads, you see JS ads, you see flat image ads -- but you never see Java ads.
In any case, I think JS won because it gave immediate gratification: you took the image that you had already placed on the page and, onmouseover, you replaced it with an animated GIF which you'd already loaded and cached. It was event-driven design with a GUI language that you already needed to know when you were making a web app in the first place -- you didn't have to learn AWT and Swing and such before you could make and place a drop-down menu; you just placed a SELECT with OPTIONs, the same as for a form.
When CSS replaced FONT tags and ECMA partly solved the problem of Microsoft trying to kill Javascript in favor of JScript, it became clear to me that JS was indeed the Language of the Web, and that HTML and CSS were just very smart declarative domain-specific languages for its GUIs. If you want a single lesson, there it is: make sure your language allows for declarative programming, and make sure your GUI language is declarative and event-driven.
Its other strengths would not necessarily have been strengths elsewhere. It's an asynchronous language with no race conditions. That's perfect for a responsive GUI, but it's probably wrong for anything which needs lots of processing power. It's got light objects and first-class functions, which is beautiful when you want to package data and write jQuery, but the cool stuff you can do with the Haskell type checker is pretty much not allowed by this model.
But those are the reasons why you might still prefer JS, even when other middle languages exist.
> You can treat it as a black box, of course: even to this day, for lots of people, Java on the web just plain doesn't work. But I think you're asking why it doesn't work, and that's much more subtle. You know who would be an interesting person to ask? An advertiser. You see flash ads, you see JS ads, you see flat image ads -- but you never see Java ads.
Well, to begin with, a typical Java applet take around 30 seconds to one minute just to load and start execution, usually suspending the whole page. There's nothing more annoying on the Internet for me than encountering an unexpected embedded Java applet. Hitting "back" and killing the Java process is almost subconscious reaction to me now. Java Web Start was actually something nice and I used it to launch programs and play games written in Java. It at least asks before hunging your browser up.
And then again, Java applets are consistently ugly. Maybe it has something to do with default GUI libraries, which look bad and break UI conventions. Only today I had to deal with a Java program that reinvented tree view, so that you couldn't rename elements without killing and reinserting them.
So yeah. Execution sucked then and still does now.
As far as why JS, source-map for debugging is a big deal here. This makes it a very good host language because it enables source debugging even when used as a compiler target.
Don't underestimate how influential Microsoft was. They were terrified of Java and did everything they could to kill it. There were problems in Sun's execution too but Microsoft's recalcitrance sealed the deal.
It's worth wondering why this is, and I don't really have an answer. In JS's infancy, Java was meant to be the Language of the Web and JS was its asthmatic younger brother. There are probably purely aesthetic problems which led to Java being overtaken by Flash, but I don't know. I sometimes like to say that Java looked consistent in every browser -- but consistently ugly. But Java is not necessarily fun to develop in either, and getting people to install Java always seemed like it was more pain than getting them to install the Flash plugin.
You can treat it as a black box, of course: even to this day, for lots of people, Java on the web just plain doesn't work. But I think you're asking why it doesn't work, and that's much more subtle. You know who would be an interesting person to ask? An advertiser. You see flash ads, you see JS ads, you see flat image ads -- but you never see Java ads.
In any case, I think JS won because it gave immediate gratification: you took the image that you had already placed on the page and, onmouseover, you replaced it with an animated GIF which you'd already loaded and cached. It was event-driven design with a GUI language that you already needed to know when you were making a web app in the first place -- you didn't have to learn AWT and Swing and such before you could make and place a drop-down menu; you just placed a SELECT with OPTIONs, the same as for a form.
When CSS replaced FONT tags and ECMA partly solved the problem of Microsoft trying to kill Javascript in favor of JScript, it became clear to me that JS was indeed the Language of the Web, and that HTML and CSS were just very smart declarative domain-specific languages for its GUIs. If you want a single lesson, there it is: make sure your language allows for declarative programming, and make sure your GUI language is declarative and event-driven.
Its other strengths would not necessarily have been strengths elsewhere. It's an asynchronous language with no race conditions. That's perfect for a responsive GUI, but it's probably wrong for anything which needs lots of processing power. It's got light objects and first-class functions, which is beautiful when you want to package data and write jQuery, but the cool stuff you can do with the Haskell type checker is pretty much not allowed by this model.
But those are the reasons why you might still prefer JS, even when other middle languages exist.