ES5 in Futures
Futures uses and will use ES5.
I'm also using Futures server side with NodeJS (and that is influencing how I'd like to reshape the API)
Even IE9 is now supporting standard JS as I understand it.
For light-weight ES5 in the browser I recommend:
With the comments removed and minified it's very small.
Note: you'll have to remove the very last line -- require('JSON') -- unless you use some client-side CommonJS require function.
There are good reasons to include support for older browsers, but
there is also a good case for not duplicating code that a client
probably already has in other JS files anyway.
3k of a client's download is well worth not having the headache of duplicating this all of the time:
function loop(val, key, obj) {
// do_stuff
}
for (x in obj) {
if (obj.hasOwnProperty(x)) {
loop(obj[x], x, obj);
}
}
This has me thinking that there should be some way to perform "feature
detection" and load additional code only when necessary. The idea
would be to have "feature plugins" in separate files that would be
loaded only if that feature wasn't implemented in the current
environment. Maybe this already exists in CommonJS or something
similar.
Google has it in their compiler toolset. Uses server-side client detection and sends a pre-optimized version of the code for that browser.
I don't know of any NodeJS or CommonJS modules that do the same and I wouldn't recommend that you try on your own.
Of course this would create additional requests instead of adding
possibly unnecessary minified code to a single big JS file. Not sure
which would be worse...
Yeah, I think that the latency of another request is greater than the cost of an extra 10kb.
When even Google is loading full background images for blogspot, iGoogle, etc, I don't see the cost of a few kb of JS as a big loss.
However, in the mobile space I agree that it is something to consider.
Thanks for the feedback Tauren.
I've got some interesting stuff coming up soon with CopyCat (some of it exists and is very functional, just not well packaged yet) and then I'll be back to working on Triforce, bringing in some concepts I found in NodeJS - specifically nStore.