Brendan Eich Explains ECMAScript 3.1 To Developers 94
VonGuard writes "On April 9, ECMA International produced the final draft for the first major update to JavaScript since 1999. It's called ECMAScript 3.1, but will soon be known as ECMAScript, Fifth Edition. You'll know it as JavaScript, the Next Generation. Mozilla will begin implementing these features after Firefox 3.5, and Microsoft is already showing prototypes behind closed doors. The question, however, is what this will change for JavaScript coders. To get those answers, I tracked down Brendan Eich, Mozilla's CTO and the creator of JavaScript. I transcribed the interview without any editorial since he explains, perfectly, what's changing for programmers. Long story short: Json will be safer, getters and setters will be standard, and strict mode will make things easier to debug."
Re: (Score:3, Insightful)
With Microsoft cooperating to improve the language, now we can move on beyond the fifth edition, toward ECMAScript harmony.
Whatever happened to Embrace, Extend, and Extinguish?
Extend is right there in bold
Re: (Score:3, Informative)
Not really. In "EEE", "extend" implies that the company unilaterally extends the standard that they've previously implemented ("embraced") with new features - for example, what MS did with Java in J++ in the past. In TFA, "cooperating" meaning "working as a part of language committee" - and that committee consists of many other companies, including direct MS competitors. There's no hidden catch here - MS is participating in proper discussion process, not overriding it.
In a similar vein, Microsoft "cooperate
Re: (Score:2)
Ah, so they can't even do EEE right anymore? ;)
I'd imagine the "Extend" bit is much harder if you're sharing your extensions with the community.
Re: (Score:2)
I remember when Microsoft was "not unfriendly" to developers, before they decided that everyone producing a broadly useful application was their competition to be either absorbed or destroyed.
It is possible for them to be competitive without being the force of destruction that they became in the mid 1990's.
very incremental (Score:2)
From TFA, it sounds like they are moving a lot of the stuff you normally find in the more popular libraries into the language itself. That makes sense, but hardly a game changing innovation that web application development companies should be gearing up for.
Re: (Score:2)
The last line from TFA, "That's the proper role of standards." describes that. Standards standardize innovations that become common - usually some common set of incompatible implementations (hence the need for standardization). It's inappropriate to use standards in an attempt to innovate. The W3C learned that lesson with xhtml 2.0.
Re: (Score:2)
How are thee irrelevant, inflammatory and offtopic? Let me count the ways...
Seriously, what the eff does this have to do with the new release of JS? Pointing out that there was a bit of a struggle between Eich/Mozilla and Microsoft about the new additions to the language would at least have been on topic, but this?
Seriously, get out of the basement, wash and stop the useless bashing. There's such a lot of useful bashing to be done...
Re: (Score:2)
"ECMA" tells it all.
Specification does not dictate implementation (Score:3, Informative)
Until this changes throughout the entire web, ECMAScript will only be that other part of css. It's just too problematic to have to code separate DOM funtionality for every browser on the market.
Re:Specification does not dictate implementation (Score:4, Insightful)
It's just too problematic to have to code separate DOM funtionality for every browser on the market.
These days, most of the forking is done in the library you're using - I rarely need to fork my code based on specific browsers anymore.
libraries are an ugly hack (Score:5, Insightful)
you should be able to code in straight javascript in all browsers the same. obviously, you can't do that now. but that doesn't justify the existence of libraries, it just means they are temporary bandaids that should go away with the implementation of the next javascript (crossing fingers)
Re: (Score:2)
As I noted in my other comment: You can code straight JavaScript in all browsers. Even eLinks and IE. If you modify the object prototypes appropriately.
Re: (Score:1)
I agree with your premise, but many libraries, in addition to papering over browser differences, offer APIs that are more attractive than the DOM (for instance, CSS selectors, which are much nicer than element collection and node traversal).
Browsers are adding selectors, but javascript implementations have been available for ~5 years ( http://paulirish.com/2008/javascript-css-selector-engine-timeline/ [paulirish.com] ), waiting for the feature to be standardized and implemented at the browser level isn't something you can
Re: (Score:2)
Until javascript can traverse the DOM with something as elegant as $('.cat').click(function(){});, I'll be using jQuery for just about ever. Otherwise, I hope you are right. All these wrapper libraries are getting out of hand.
Re: (Score:2)
WTF? I've written JavaScript before, but bever used jQuery. What the hell is that code doing? Clicking on all the ".cat"s using an empty function? Huh?
No seriously, why would a method named "click" take an argument? Any why would a valid value for that argument be an empty unnamed function?
lol (Score:2)
You really think I was gonna fill in the guts of a sample function? .click() [jquery.com] hooks the onclick event.
Re: (Score:1)
seriously, RTFM [jquery.com]. This code registers an onclick callback to objects with css class cat. Try doing that with the built in dom methods in less than 10 lines of code.
Re: (Score:2)
Makes about as much sense as what you said. Javascript libraries do more than just fix browser inconsistencies, they add many useful features and improve a programmer's life significantly.
Re: (Score:1)
For some features, specification is just playing catch-up to the implementation.
The world couldn't just sit around and wait for JSON.parse.
Re: (Score:2)
if(window.addEventListener) {
window.addEventListener('load', init, false);
} else if(window.attachEvent) {
window.attachEvent('onload', init);
}
It's unfortunate, but not a huge bother. It's rare in my day-to-day JS programming that I run into major compatibility issues beyond whether or not a particular feature is implemented in various JS engines.
Re: (Score:3, Informative)
Yeah right. It's just that I did exactly that from 2001-2006.
You write some intermediate standard layer, and you're done with it.
Maybe you just don't know how to abstract things away. ^^
JavaScript is surprisingly powerful. And you can even fix the whole missing/buggy DOM functionality in IE, by adding functions to the prototypes of the DOM objects.
For CSS fixes, there is even a library.
Re: (Score:2)
Well not necessarily. Ajax libs like Dojo abstract away the differences so the end program doesn't have to care (too much) whether they're on IE, Firefox or something else. The client code just makes an xml http
Very little of the *language* is forked... (Score:2)
FTA: A lot of JavaScript is forked. If the DOM is IE, use this version of the code, otherwise use this.
Not much of *Javascript* itself is forked. The *DOM* is quite thoroughly forked. One might even say forked over. But as other people have pointed out, Prototype and Dojo and jQuery and the like tend to mitigate that problem.
Re:OOP? (Score:4, Insightful)
Sanity? (Score:5, Insightful)
JavaScript does OOP in a sane manner. It's not the same manner as many traditional OO languages, to be true -it's prototype-based instead of class-based- but it's every bit as sane in its own way. It's just different.
The major reason you find OOP in JavaScript to be "insane" is that you are tearing your hair out trying to shoehorn in this particular paradigm that the language wasn't designed to use: sure, you can do it, but it's a lot of extra effort for very little gain in the end. That's not a problem with the language, but with programmers who resist the flow of that language. Just let JavaScript be JavaScript, and you'll find that things get much saner, or at least a lot less maddening.
Seriously: what harm ever came from learning new ways to do things?
Re: (Score:3, Insightful)
Ahh the sign of someone who doesn't understand the difference between OOA/OOD and OOP.
The 4-digit /. ID you were replying to was referring to classes as they appear in 3GLs like C++, Java and C#, not to the "OO" word "class".
And that was perfectly clear from the context.
Go read good books on OO BitZtream, and try again later.
Re:OOP? (Score:4, Insightful)
Also, you don't have to set the prototype all at once in a single object. The prototype keyword is used for functions that are common to all instances of the object; you can just as easily set the functions inside the constructor, but that creates a new function object for each instance instead of using one function object defined in the prototype and thus requires more memory. This allows you to change your object's behavior on the fly (if you so choose).
In short, OOP in ECMAScript is not 'totally retarded' at all, just outside your comfort zone. Try it first, THEN flame it, if you still think it's awful.
Re:OOP? (Score:5, Informative)
ECMAScript is a prototypal functional programming language. You don't just set members of an object by defining its prototype in an object literal.
You can also, by the power of closures, have private functions, private variables, and protected functions. (ECMAScript is interesting in that public member functions cannot access private variables, but protected functions can. Downside is that protected functions (defining them as this.foo = function() {}; in the constructor) are created new for each instance of the object, unlike the prototype (public) members.
While ECMAScript isn't built to enhance tail recursion, it's actually possible. For example, a continuous passing style fibonacci sequence calculator [warfangled.com].
Not quite as readable as haskell or lisp, but still - proves that JavaScript is a true functional programming language.
Re: (Score:2)
You know that for many programmers, that's sort of like saying "not quite as humid as Death Valley", right?
jQuery() (Score:3, Insightful)
As long as using jQuery doesn't change, I'm good. :)
Re: (Score:2)
jQuery is what JavaScript *should* have been all along.
Re: (Score:2)
I think you're confusing the DOM api and javascript. jQuery makes the DOM api what it should have been all along.
Re: (Score:2)
This history of javascript and the DOM is pretty complex and interesting. For example, the practice of wrapping native DOM objects has its roots in a cross-browser hack. IE's implementation of the DOM used COM, which meant that methods couldn't be added at runtime (maybe things got better with .net... I wouldn't know).
It turned out to be really useful, even aside from the cross-browser aspect. It allows jQuery to work with other libraries, and even multiple instances of itself. It gets around the problem of
Re: (Score:2, Insightful)
jQuery is what JavaScript *should* have been all along.
No, jQuery is a very good javascript framework, but its api should have no part -- at least yet -- in javascript itself.
Right now, the differences in coding an application with jQuery's framework compared to Ext/Prototype/GWT/etc are greater than the differences in coding javascript for IE vs Firefox. Frameworks are a personal choice of how you prefer to code, and one single framework should not be forced onto all coders.
To say jQuery is what JavaScript should have been is like saying that Ruby on Ra
Re: (Score:1)
While I hope, like the sibling poster mentioned, that the DOM api is improved, I certainly don't want jQuery to become the next standard of JavaScript.
$("i").#{certainly}.#{agree}.childNode[0].with_that
JavaScript, the Next Generation (Score:4, Funny)
I fear for all those poor websites with red backgrounds...
Re: (Score:1)
Let's get this out of the way now (Score:5, Funny)
I'm holding out for ECMAScript 3.11 for Workgroups!
what a joke (Score:2)
Everybody knows TNG just copied half its stuff from the original!
Re: (Score:2, Funny)
Meh, they're just Enterprising!
Json vs. XML (Score:3, Funny)
Json has dethroned XML for pure data interchange
</quote>
Somehow I don't think so. "AJAJ" just doesn't have quite the same ring to it.
Re: (Score:2)
Somehow I don't think so. "AJAJ" just doesn't have quite the same ring to it.
Use YAML (a superset of JSON), and then you can have AJAY.
Re: (Score:3, Interesting)
Json has dethroned XML for pure data interchange
I wish I could figure out why this is so, given that XML was already a standard when JSON was invented, and is widely supported and just as compact. Here's an example of a JSON specification:
{
"name": "Jack (\"Bee\") Nimble",
"format": {
"type": "rect",
"width": 1920,
Re: (Score:2)
Well... JSON wasn't really "invented". It's really just the syntax for an object literal in javascript. JSON parsing is not much more than eval() and a regular expression.
It works beautifully.
Not going to touch the rest of your comment. JSON is more useful in this context than xml.
Btw, Crockford's presentations are really entertaining: http://www.youtube.com/watch?v=hQVTIJBZook [youtube.com]
Re: (Score:2)
Well... JSON wasn't really "invented". It's really just the syntax for an object literal in javascript. JSON parsing is not much more than eval() and a regular expression.
This actually makes sense. Thanks.
I can see that the advantage of leveraging an in-built language capability can plausibly out-weigh the other advantages of XML, particularly, as others have pointed out, you have to suck the XML parser down over the wire. While it would obviously be possible to support a very light-weight subset of XML t
Re: (Score:2)
Re: (Score:2, Insightful)
name = eval(jsonString).name
var xmlparser = new ActiveXObject("MSXML2.DOMDocument.3.0");
var doc = xmlparser.loadXML(xmlString);
name = selectSingleNode("name").value;
That's one reason.
Re: (Score:2)
Are you willing to claim that a proper XML parser able to parse XML in its entirety is thinner (smaller, faster) than a JSON parser able to parse JSON in its entirety? I would be very surprised if this were true.
Re: (Score:2)
Well anyone can present a contrived example...
But in actual practice, XML contains a lot of redundancy in the form of open/close tags.
Or do you think everything should be expressed as attributes?
Re: (Score:2)
Well anyone can present a contrived example...
My "contrived example" was straight out of the JSON docs, so if it was a contrivance it wasn't MY contrivance.
But in actual practice, XML contains a lot of redundancy in the form of open/close tags.
As I said in reply to another comment, if that's your actual practise, you're doing it wrong. Base types should be expressed as attributes, obviously. There is absolutely no reason to express anything as an element unless it has a complex structure.
This is why I've
Re: (Score:2)
Your XML version wasn't out of the JSON docs, that was your own contribution, and it was clearly minimizing use of tags and maximizing use of attributes.
If you're going to claim that's just the "right way", kindly link to some supporting documentation.
Would you say this is "bad" XML?
<menu>
<menu-item>
<portion unit="mL">250</portion>
<name>Small soft drink</name>
</menu-item>
JSON not always fatter (Score:2)
JSON's not always fatter. Particularly when you have information stored as child nodes rather than attribute nodes (one-many relationships rather than one-one relationships tend this way), XML can get fatter pretty quickly.
I suspect the JSON love has to do with the fact that if you're already working in Javascript, it's just more javascript, and there's zero mystery about how to work with it. Not that XML is rocket science, but with JSON, it's pretty much as easy as eval() if you trust the server.
Overall, I
Re: (Score:2)
Because XML isn't as compact in most real-world cases (which don't involve only one parent entity with a one-character name with exclusively empty children, meaning you have a much higher ratio of wasted characters in end tags than in your carefully-chosen example.) And because in JavaScript, JSON from a trusted source is trivially parseable with eval(), whereas
Re: (Score:1)
Re: (Score:1)
Try a list
JSON:
{
listofstuff: [1, 2, 3, 4, 5, 6],
properties: { x: "asdf", y: "qwer" }
}
XML: />
<root>
<listofstuff>
<i>1</i>
<i>2</i>
<i>3</i>
<i>4</i>
<i>5</i>
<i>6</i>
</listofstuff>
<properties x="asdf" y="qwer"
</root>
This kind of foible really turns me off xml. Not to say XML doesn't have its place, but for AJAX applications I think JSON is much more
What (Score:2)
{"name":"Jack (\"Bee\") Nimble","format":{"type":"rect","width":1920,"height":1080,"interlace":false,"frame rate":24}}
<o name="Jack ("Bee") Nimble"><format type="rect" width="1920" height="1080" interlace="false" frame_rate="24"/></o>
Anyway, it's a difference of 8 characters in JSON's favor. Unlike XML attributes, no whitespace between JSON properties is necessary. And for that matter, while they can be shoehorned to present the same information, they can serve somewhat different
Summary of JavaScript changes? (Score:1)
Anyone have a link?
Could we change the friggn name? (Score:3, Funny)
Old story, "no it's not java" or "ECMAwhat?"
We get a new rev, add a name change update; let's call it something cool, oh, say ruby++ ?
Re: (Score:1)
Re: (Score:1)
let's call it something cool, oh, say ruby++ ?
I think you mean, "ruby-2sday"...
confusing names (Score:3, Informative)
The names and version numbers are really confusing. The following is my understanding, which may be wrong -- if so, please correct me.
ecmascript 4==javascript 2==actionscript 3 ... If I'm understanding correctly, this was overambitious, turned out to be a dead end, won't happen.
ecmascript 3.1==ECMAScript, Fifth Edition ... This seems to be the more modest thing that they backed off and got a consensus for instead.
Re: (Score:2)
ECMAScript 3.1 was used because they decided to back off the goals of ECMAScript 4.0 - 3.1 more readily describes the renewed goals as being less ambitious, only an incremental improvement over 3.0. When it's done though, it will be a whole new version - fifth edition or ECMAScript 5.0.
That's my understanding at least. :-)
Sweet! (Score:5, Interesting)
First, JavaScript is a very nice language indeed. If you've never learned functional programming, JavaScript is a good language to learn in. Why? You can actually do real work while learning! As for the new language spec...
Getters and setters are nice, but I'm not sure they serve a purpose in javascript--javascript is more functional than it is OO and I think people learning the language should change mindsets rather than the langage get bastardized to something it is not. I dunno, somebody can challenge me on this.
Good to see they are thinking about adding a "use strict". You aren't an adult language until you have a way to force variable declaration. Hopefully "use strict" will apply to a module or block, not to the entire project. I want to "strictify" my own JavaScript, but I dont want the browser to choke on some sloppy copy-and-paste deal from AdSense or analytics.
Lastly, JSON. There are a couple "gotchas" with it... namely when you generate JSON using a loosely typed language like Perl and try to feed it into a strongly typed language like C# (i.e. silverlight). Depending on the serializer [codeplex.com] / deserializer [microsoft.com] used on the strongly-typed side, you'll run into things.
For example, the deserializer in C# just might choke on this: // it will puke on this: // i am a string! // I am a postgresql date, but I'd also barf on ISO8601 // puke free: // I am an int! // i am a legit Date()
"themes": [
{
"theme_id": "34",
"last_mod": "2009-04-09 13:04:27.232-07"
},
{
"theme_id": 34,
"last_mod": new Date(3000, 00, 01, 00, 00, 00)
}
]
Why? Perl serialized [cpan.org] the integers as a string. Depending on the deseralizer, it might choke on those strings if it was expecting a number. YUI would also be pissed off about the date not being a javascript Date()--good luck finding a serializer that produces such a thing! My point? These are some surprise gotchas you have to worry about when dealing with JSON. Not sure who is to "blame"--perl for being loosely typed, the deserializers for being to strict. This would be a problem with XML as well though.
Re: (Score:2)
First, JavaScript is a very nice language indeed.
Like any language, that depends on what you're trying to do. If you want to format the output of a date, there's not much built-in, so you have to do it yourself. If you want proper hash support, you're screwed. It can emulate it to a certain extend, but only goes so far.
I'd _much_ rather see a scriptable version of D.
clean up your language (Score:2)
C# and Perl happen to be also strongly typed and losely typed, respectively, but that isn't essential to your example. The distinction you're looking for isn't "strongly typed" vs "loosely typed", but "statically typed" vs "dynamically typed".
Re: (Score:1)
Most of the functional programming techniques I know, I learned in Perl.
It's interesting. I am sufficiently conversant in Emacs lisp to do significant amounts of useful stuff (including custom major modes for special editing situations), but I never understood lambda expressions in lisp. In Perl, though, anonymous subroutines are so straightforward, I immediately understood them and was able to start using them
bedug (Score:1, Troll)
aHahahahahahahahahahahahaha. Why it's the best thing about Javascript, writing the same code*browers different ways, and with chrome and safari Javascripting is just gonna get more and more fun. More Fun, MORE F.U.N.
The evil javascript hurts me. Evil I tells you!!!!
Re: (Score:2)
Surely other people who code in javascript have had the same issues as I do. Firebug is great but it doesn't help when you are trying to make sure your javascript works under IE. And no I don't want to buy all the proprietary Microsoft tools to debug javascript for IE and yes I do know about the javascript debug option under IE.
I'm not a Troll, Hrumph!!!
I'm glad they took an iterative approach (Score:5, Insightful)
It sounds like they decided to go with shoring up the language as it is currently used rather than make sweeping new changes. Good for them. I'm not sure if it was Adobe's doing or Macromedia's, but they really threw out the baby with the bathwater with the "transition" from ActionScript 2 to ActionScript 3. Rather than fixing up the obvious problems with AS2, like silently swallowing errors and gaping holes in the functionality of core objects, they abandoned it entirely and replaced it with some bizarre mutant language from a parallel dimension. I still have to wonder why, if they were willing to completely abandon both backward compatibility and developer familiarity, they didn't just decide to switch to an existing language. As far as I can tell, the only thing that AS3 really accomplished was to reimplement Java, and poorly.
For a while, it looked like the next version of JavaScript was following down a similar path. Glad to see that's not going to be the case.
Re: (Score:2)
I agree with most of what you said. AS3.0 made things a lot more strict, without addressing the main problem with AS2 - all silent errors. They can still fix it, that strictness is useful for larger undertakings and library authors (the browsers are even adding it to JavaScript).
The fix, default the timeline (and maybe even the entire Flash IDE) to non-strict mode, and add in a slew of warnings instead of throwing application halting errors all over the place. Auto-type marshaling is great! As long as you g
Re: (Score:2)
I'm not taking sides on AS2 vs. AS3, and I'm not saying AS3 is necessarily a bad language. I'm just suggesting that it seems to me that AS2 could have been improved upon substantially without throwing out the entire language. Personally, I have relatively limited experience programming either version of Flash, and I wouldn't mind keeping it that way.
On the other hand, I have many years of experience with JavaScript, which I consider to be a wonderfully powerful and expressive language. I would hate to se
A few more names please (Score:1, Offtopic)
Re: (Score:2)