Slashdot Mirror


Brendan Eich Explains ECMAScript 3.1 To Developers

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."

23 of 94 comments (clear)

  1. Re:What's the catch? by Rik+Sweeney · · 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

  2. Specification does not dictate implementation by riyley · · Score: 3, Informative

    FTA: A lot of JavaScript is forked. If the DOM is IE, use this version of the code, otherwise use this.

    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.

    1. Re:Specification does not dictate implementation by e4g4 · · Score: 3, 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.

      --
      The secret to creativity is knowing how to hide your sources. - Albert Einstein
    2. Re:Specification does not dictate implementation by Hurricane78 · · Score: 2, 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.

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
  3. jQuery() by Anonymous Coward · · Score: 3, Insightful

    As long as using jQuery doesn't change, I'm good. :)

    1. Re:jQuery() by chdig · · 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 Rails is what Ruby should have been, or that symfony or CakePHP is what PHP *should* have been. ie:apples vs oranges comparison.

      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.

  4. JavaScript, the Next Generation by tttonyyy · · Score: 3, Funny

    I fear for all those poor websites with red backgrounds...

    --
    biopowered.co.uk - catalytically cracking triglycerides for home automotive use since 2008. Just say no to big oil!
  5. Let's get this out of the way now by Anonymous Coward · · Score: 5, Funny

    I'm holding out for ECMAScript 3.11 for Workgroups!

  6. Re:OOP? by johnnysaucepn · · Score: 4, Insightful

    Probably around the time you realise that object-oriented doesn't mean class-oriented.

  7. Sanity? by Millennium · · Score: 4, 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?

    1. Re:Sanity? by Anonymous Coward · · 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.
       

  8. Re:OOP? by BlitzTech · · Score: 4, Insightful

    If you don't understand the expressive power and usefulness of functions as first class objects, you should really try using JavaScript differently. As for why you're using Object instances as classes, have you never used Java?

    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.

  9. Re:OOP? by bishiraver · · 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.

    Not quite as readable as haskell or lisp, but still - proves that JavaScript is a true functional programming language.

  10. Json vs. XML by dmmiller2k · · 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.

    --

    "No matter how cynical you get, it is impossible to keep up." -- Lily Tomlin

    1. Re:Json vs. XML by radtea · · Score: 2, 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,
                      "height": 1080,
                      "interlace": false,
                      "frame rate": 24
              }
      }

      And here's exactly the same thing in XML:

      <o name="Jack (&quot;Bee&quot;) Nimble">
      <format type="rect" width="1920" height="1080" interlace="false" frame_rate="24"/>
      </o>

      The XML is 129 characters, the JSON is 142 characters (counting each white-space sequence as just one character in both cases.)

      So JSON is fatter than XML and less standardized, or was when it was invented. There is a minor impact on the naming because XML names can't have spaces in them, but this seems to me insufficient to justify the invention of an entirely new language when a simple XML specification would have worked just as well.

      I've looked at this question a couple of times, and never been able to find any argument other than "Badly written XML can be incredibly bloated compared to JSON" but this seems to me entirely inadequate. I'd really like to be enlightened regarding alternative justifications for JSON.

      --
      Blasphemy is a human right. Blasphemophobia kills.
    2. Re:Json vs. XML by beegeegee · · Score: 2, Insightful

      var name;
      //JSON
      name = eval(jsonString).name

      //XML (at least in IE)
      var xmlparser = new ActiveXObject("MSXML2.DOMDocument.3.0");
      var doc = xmlparser.loadXML(xmlString);
      name = selectSingleNode("name").value;


      That's one reason.

  11. Re:what a joke by x78 · · Score: 2, Funny

    Meh, they're just Enterprising!

    --
    Don't panic
  12. Could we change the friggn name? by sammyo · · Score: 2, 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++ ?

  13. libraries are an ugly hack by circletimessquare · · Score: 4, 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)

    --
    intellectual property law is philosophically incoherent. it is your moral duty to ignore it or sabotage it
  14. confusing names by bcrowell · · Score: 2, 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.

  15. Sweet! by coryking · · 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 / deserializer used on the strongly-typed side, you'll run into things.

    For example, the deserializer in C# just might choke on this:
    "themes": [ // it will puke on this:
            {
                    "theme_id": "34", // i am a string!
                    "last_mod": "2009-04-09 13:04:27.232-07" // I am a postgresql date, but I'd also barf on ISO8601
            }, // puke free:
            {
                    "theme_id": 34, // I am an int!
                    "last_mod": new Date(3000, 00, 01, 00, 00, 00) // i am a legit Date()
            }

    ]

    Why? Perl serialized 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.

  16. I'm glad they took an iterative approach by drew · · Score: 4, 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.

    --
    If I don't put anything here, will anyone recognize me anymore?
  17. Re:What's the catch? by shutdown+-p+now · · Score: 2, 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 "cooperates to improve" ISO C++, by having a number of people on the corresponding ISO committee (e.g. Herb Sutter). The same goes for HTML5, WS-* stack, XQuery, and many other standards that are implemented in whole or part in MS products.