JS: The Good, the Bad and the Ugly 12

An article comparing JScript and VBS got me some ideas about what I think should be added to JS 1.6.


I like the Date object in JS but it needs a lot of improvements. These following things are really missing:

  • Localized weekday name
  • Localized month name
  • Week start day
  • Week number (localized because it is not the same all over the world
  • parse is totally useless because it only accepts US date format. It should allow a localized date string and take second argument containing the pattern.
  • There should be a way to get the pattern, much like how SimpleDateFormat works in Java.


We definately need a format method that works much like printf in C and the % operator in Python. This one should work with the date time format mentioned above.

There is also a need for a StringBuilder class since concatenation is too slow to do on imutable String objects. This is easy to implement in JS but letting the host environment implement this could improve performance quite a bit.


See Array Extras.

These methods should also work on hashes (Object) and other collection like objects like the DOM NodeList.


  • There is often a need for a toHashCode() method that returns a unique id of the object
  • Getters and setters (Mozilla has these in JS1.5) but they need to be widely supported to allow real world usage
  • Marking fields as enumarable or not. ActionScript has had this for a long time.
  • A way to override the [] operator. I mean right now there is no good way to extend Array or Object to make it behave like a collection without adding a method.


  • Constants like in JS1.5
  • for each loops that loops over the elements in an Array and the fields in an Object. (E4X really blew it here and broke the for in loop semantics.)
  • Depreciate with since it is really bad in dynamic lanugages
  • Add tuples support
  • Fix the constructor property so that it points at the constructor used to create the object.
  • Allow sub classing of built in objects like Array, Function and Date as well as DOM objects. Just imagine being able to create a class that extends Element
  • yield/generator support like in Boo or Python.
  • http://www,dept-z.com Tom Trenka

    Byte Arrays! You forgot byte arrays!

    Oh, and full on operator overloading would just f*cking rock :)

  • http://erik.eae.net Erik Arvidsson

    Yes. Totally. Using arrays with Number/Boolean is very slow and using Numbers with bitwise operator is limited to 32 bits. I guess the best thing to do today is to use a combination of the 2?

    Yeah, why limit the operator overloading to []? I would really love to be able to overload ‘+’ so that we can implement event listeners like in C#.

    I also like the unit things from JS2 but the line has to be drawn somewhere.

  • M. Schopman

    I would love to see “metadata” features so we can automatically generate documentation. The scripts become larger and more complex, documentation is necessary. Something like C# has, with /// summary

    Not to mention a simple super scope. Absolutely necessary :)

    In overall beter focus on providing editors with more information and features for Javascript coding.

  • http://erik.eae.net Erik Arvidsson

    Metadata for documentation is not really needed in my opinion. It works well with jsdoc and similar tools already. JS2 has support for attributes (like JScript.NET)

    Super scope? Necessary? not really, but convenient. You can invoke super and super methods using call and apply on the function objects in question.

    I agree that editors totally suck today but I don’t think it is a problem that the syntax and semantics of the language should care about.

  • http://dean.edwards.name/ Dean Edwards

    If we just got getters and setters I’d be happy.

  • http://www.wdonline.com Jeremy

    I’m with Dean. While the list is nice, I’d be jumping up and down with joy if getters and setters were implemented. What a wonderful world life would be.

  • http://erik.eae.net Erik Arvidsson

    I agree with getters and setters being the most important thing here. I’m using ul elements because the list is unordered ;-)

  • http://www.nczonline.net/ Nicholas

    Oh man, date weeks drive me nuts. I had to come up with an algorithm for that at my last job, and it was painful. So many different standards, so little time.

    In regards to stringbuilder: Firefox actually fixed the problem with string concatenation. I had created a StringBuffer object for my book before Firefox 1.0 was released, and now I find that Firefox’s native string concatenation is actually faster than my StringBuffer (IE’s is still significantly slower). While having a native StringBuffer would be nice, it would also be nice if JavaScript worked the same way as Java in that behinds the scenes it used a string buffer so we didn’t have to worry about it.

    Marking fields as enumerable is a big one for me as well. I’m sick of overriding toString() only to have it show up in a for..in loop.

  • http://erik.eae.net Erik Arvidsson

    I guess += can be optimized for strings but it makes other things a lot harder to implement (in the interpreter that is). But as long as it works I’m happy. I didn’t know Java optimized this. I know JS.NET gives a warning when you use += on Strings.

  • http://dhtmlkitchen.com Garrett Smith

    Those would be very good things to have, Erik. Very practical and wouldn’t be that hard to add to the language.

    * String could also have instance methods:
    trim, startsWith and endsWith.

    * string.match and RegExp.exec should both be fixed to always return and array, and never null, thus eliminating the need to make an extra check for null. So you could do this:

    var matches = “foo”.match(/o/);
    for(i = 0; i

  • http://erik.eae.net Erik Arvidsson

    Garrett: You ended up sending your comment to the JS1.6 thread

  • Pingback: nrpneinzc()