views:

242

answers:

8

Javascript is an incredible language and libraries like jQuery make it almost too easy to use.

What should the original designers of Javascript have included in the language, or what should we be pressuring them into adding to future versions?

Things I'd like to see:-

  • Some kind of compiled version of the language, so we programmers can catch more of our errors earlier, as well as providing a faster solution for browsers to consume.
  • optional strict types (eg, being able to declare a var as a float and keep it that way).

I am no expert on Javascript, so maybe these already exist, but what else should be there? Are there any killer features of other programming languages that you would love to see?

A: 

File IO is missing.... though some would say it doesn't really need it...

jle
File IO is part of only a few languages like PERL. Mostly it is part of a language's libraries.
Justice
the question was not strictly about syntax
jle
A File IO library was, if I recall properly, available in an experimental version of Mozilla browser about 5-6 years ago.
George Jempty
+4  A: 

Read Javascript: The Good Parts from the author of JSLint, Douglas Crockford. It's really impressive, and covers the bad parts too.

erenon
Just be careful. Like all experts, Crockford has strong opinions, some of which may be questionable.
staticsan
+1  A: 

The ability to use arrays/objects as keys without string coercion might've been nice.

chaos
+1  A: 

What should the original designers of Javascript have included in the language, or what should we be pressuring them into adding to future versions?

They should have got together and decided together what to implement, rather than competing against each other with slightly different implementations of the language (naming no names), to prevent the immense headache that has ensued for every developer over the past 15 years.

Perspx
+4  A: 

One thing I've always longed for and ached for is some support for hashing. Specifically, let me track metadata about an object without needing to add an expando property on that object.

Java provides Object.getHashCode() which, by default, uses the underlying memory address; Python provides id(obj) to get the memory address and hash(obj) to be customizable; etc. Javascript provides nothing for either.

For example, I'm writing a Javascript library that tries to unobtrusively and gracefully enhance some objects you give me (e.g. your <li> elements, or even something unrelated to the DOM). Let's say I need to process each object exactly once. So after I've processed each object, I need a way to "mark it" as seen.

Ideally, I could make my own hashtable or set (either way, implemented as a dictionary) to keep track:

var processed = {};

function process(obj) {
    var key = obj.getHashCode();

    if (processed[key]) {
        return;    // already seen
    }

    // process the object...

    processed[key] = true;
}

But since that's not an option, I have to resort to adding a property onto each object:

var SEEN_PROP = "__seen__";

function process(obj) {
    if (obj[SEEN_PROP]) {    // or simply obj.__seen__
        return;    // already seen
    }

    // process the object...

    obj[SEEN_PROP] = true;   // or obj.__seen__ = true
}

But these objects aren't mine, so this makes my script obtrusive. The technique is effectively a hack to work around the fact that I can't get a reliable hash key for any arbitrary object.

Another workaround is to create wrapper objects for everything, but often you need a way to go from the original object to the wrapper object, which requires an expando property on the original object anyway. Plus, that creates a circular reference which causes memory leaks in IE if the original object is a DOM element, so this isn't a safe cross-browser technique.

For developers of Javascript libraries, this is a recurring issue.

Aseem Kishore
My wishlist item would mostly address what you're looking for, too.
chaos
True -- I've given your answer an upvote. I wanted to clarify the scenario.
Aseem Kishore
for your specific example of DOM objects there should be a way, since jquery manages to create uniqued IDs for them (used those internally).for the general case of javascript objects this is harder
oberhamsi
+1  A: 

Javascript is missing a name that differentiates it from a language it is nothing like.

Triptych
Well, the syntax was deliberately made to be Java-like, so I wouldn't say "nothing like." Without the Java influence, Eich probably would have made the syntax like Self or Scheme. :-)
Nosredna
what like ECMAScript?
Darko Z
scheme-like language, java-like syntax.
Triptych
Nosredna.... Eich didn't come up with the name "JavaScript"... originally, I believe, it was called LiveScript.
J-P
JavaScript is called JavaScript because of a marketing deal between Sun and Netscape; the trademark is still held by Sun, but the Mozilla Foundation holds a license
Christoph
Eich didn't come up with the name JavaScript. Originally it was called Mocha, then LiveScript. What Eich says: "Whether any existing language could be used, instead of inventing a new one, was also not something I decided. The diktat from upper engineering management was that the language must "look like Java"."
Nosredna
A: 

Any semblance of logic.

Janie
+1  A: 

There are a few little things it could do better.

Choice of + for string concatenation was a mistake. An & would have been better.

It can be frustrating that for( x in list ) iterates over indices, as it makes it difficult to use a literal array. Newer versions have a solution.

Proper scoping would be nice. v1.7 is adding this, but it looks clunky.

The way to do 'private' and 'protected' variables in an object is a little bit obscure and hard to remember as it takes advantage of closures and how they affect scoping. Some syntactic sugar to hide the mechanics of this would be fabulous.

To be honest, many of the problems I routinely trip over are actually DOM quirks, not JavaScript per se. The other big problem, of course, is that recent versions of JavaScript have interesting and useful things, like generators. Unfortunately, most browsers are stuck at 1.5. Apparantly only FireFox is forging ahead.

staticsan
Nosredna
staticsan
Well I agree the + sucks. Confuses people all the time.
Nosredna