Java Script Rocks

JavaScript Pros: (Counter to JavaScriptSucks)

And JavaScript 1.7 is borrowing from PythonLanguage:


JavaScript is a great language, supports OO, Prototypical, Functional, and Procedural paradigms. To the best of my knowledge, on the power/availability scale, nothing can touch it. Most of the power of Lisp, with C's syntax and widely available and accepted, unlike Lisp and SmallTalk, most of us are actually allowed to use JavaScript. First class functions, lexical closures, automatic delegation, dynamic typing, prototype based, just about every feature you'd have in your wishlist. Hell, you should be thankful such a flexible language is available in nearly every browser, and natively in the Windows shell (really? or just through WindowsScriptingHost?), you could be stuck with VBScript.

The RhinoInterpreter from Mozilla comes with a shell out of the box. Scripts have access to the entire java platform, so this shell can do anything you want it to.

Many people who think JavaScriptSucks, don't know JavaScript well enough, or are really complaining about BrowserDomSucks? and wrongly blaming JavaScript.


In situations where users were migrating from local excel sheets to an html based interface that stored the data on a server, I found JavaScript very helpful. They wanted for instance to enter tabular data and scroll up and down with the headers and side column fixed similar to how they had it in excel ("freeze panes") the only way to do that was with scripting. You could use VBScript but given the server-side code was C and Java, JavaScript was more similar (and some users had Netscape). There was no way to avoid being "visually quite as fancy" since the UI had to be in HTML, and they would have rejected it if the look and feel was not as dynamic as excel. JavaScript gives a lot of options. I agree keep as much code server side as possible but to make "ergonomic" user interfaces, JavaScriptRocks.


JavaScriptSucks expresses the opposing view.


I agree that mostly JavaScriptRocks, but it has a couple of warts:

DouglasCrockford said that the arguments array was originally an object in JavaScript 1 because it had no arrays, just objects (which are also dictionaries). When arrays were added in JavaScript 2, it was meant to be an array, but was left as an object with a length property as a bug. Microsoft copied all the bugs in Netscape's JavaScript excruciatingly faithfully when they made JScript, so it now existed in IE as well. When the time came to standardise JavaScript at ECMA, Microsoft vetoed changing any of these bugs under the policy they had then of never making any change that could break an existing program. Two other examples are: Another reason why arguments isn't an array: would you really want
 function foo(arg1, arg2, arg3)
 {
   arguments.unshift('blah');
   alert('arg1='+arg1+',arg2='+arg2+',arg3='+arg3);
 }
 foo('arg1','arg2');
to alert "arg1=blah,arg2=arg1,arg3=arg2"?


Yes, it rocks! If you think otherwise, you never saw GreaseMonkey in action!

--OsiasJota?


It's not quite prototypical, but doesn't exaclty have classes either. Some would call that a problem, but I think that it's elegant. There are no classes, only functions which happen to make objects. new Something() is a wart, but other than that, I like it. Just tell me if this works:

     function Accumulator(a) {
         this.a = a
     }
     Accumulator.prototype = {
         add : function (b) {this.a += b},
         sub : function (b) {this.a -= b},
         get : function ()  {return this.a}
     }
     var acc = new Accumulator(0)
     acc.add(10)
     acc.mul = function (c) {this.a *= c}
     acc.mul(10)
     alert(acc.get()) // Should be 100.

This does indeed work!


CategoryJavaScript


EditText of this page (last edited June 9, 2014) or FindPage with title or text search