ECMAScript 4

Recently I have been reading over the ECMAScript 4 language overview whitepaper to see what tasty things are in it. There are some really great features, one being able to create classes. Here is a real basic example…

class Website {

   // A property

   var url;

   // Constructor

   function Website(_url){
      url = _url;
   }

   // Getter

   function get webURL(){
      return url;
   }

   // Setter

   function set webURL(_url){
      url = _url;
   }

}

// Lets extend it

class Feed extends Website {

   var desc;

   var feed;

   function Feed(_feed, _desc){
      desc = _desc;
      feed = _feed;
   }

   function getFeed(){
      return feed;
   }

   function getDesc(){
      return desc;
   }

}

…and running it the interpreter…

>> intrinsic::load("tests/test.es");
>> var website = new Website("http://blogs.pixeldepth.net/Peter/");
>> website.webURL
http://blogs.pixeldepth.net/Peter/
>> var feed = new Feed("http://blogs.pixeldepth.net/Peter/feed", “Recent posts");
>> feed.getFeed()
http://blogs.pixeldepth.net/Peter/feed
>> feed.getDesc()
Recent posts

Cool stuff, and it doesn’t stop there. I would recommend checking out John Resig’s blog, he has been posting about ECMAScript alot lately. Here are his slides from one of his talk…

For more info, have a read of John’s blog…

http://ejohn.org/blog/

Tags: ,

Saturday, November 10th, 2007 JavaScript, Programming

3 Comments to ECMAScript 4

  1. I’m not sure how different that presentation is from the one Eich gave a year or so ago on JS2.0 and the lead-up to it, but hadn’t noticed packages were in it before. Still a couple of years away though, and I’m guessing uptake won’t be brilliant til IE9/IE10?

  2. James on November 10th, 2007
  3. Been keeping up to date on things recently, and have been reading the debate…

    Link
    Link

  4. Peter on November 10th, 2007
  5. Sounds pretty cool, I had a look at the site and it seems to have a lot implented.
    I’m probably not going to use it because I hardly ever do js, but I’m still gonna try it out :)

    Thanks for the link.

  6. Xikeon on November 19th, 2007

Leave a comment

What Am I Doing?

Search

 

Categories