Main

May 15, 2008

ECMAScript 4 Object Initializers and Type Annotations

My previous post was about ECMAScript 4 object initializers and fixtures. In this post, I'm going to talk about another new feature of ECMAScript 4 object initializers: type annotations. That's right, in ES4 you'll be able to place type annotations on object initializers. To recap, an object initializer, a.k.a. an object literal, is often used in ActionScript 3 instead of the new operator to create an instance of the Object class. For example:

var techWriter:Object = {fname:"Francis", lname:"Cheng", company:"Adobe"};

Continue reading "ECMAScript 4 Object Initializers and Type Annotations" »

April 16, 2008

Object Initializers and Fixtures for ECMAScript 4th Edition

A recently released ECMAScript 4 draft specification for object initializers includes significant enhancements to the expressive power of object initializers. This post focuses on the ability to designate specific properties as fixtures, which is not possible in ECMAScript 3rd edition or ActionScript 3.0.

You may have used object initializers in ActionScript 3.0 before. They provide an easy way to assign a literal value to a variable of type Object. For example, in ActionScript 3.0, you may see something like:

Continue reading "Object Initializers and Fixtures for ECMAScript 4th Edition" »

March 31, 2008

New Draft of ECMAScript 4 Edition Grammar Released

Adobe's Jeff Dyer has released a new draft of the ECMAScript 4th Edition normative grammar. The updated draft is available in both PDF and XLS formats. Here are the relevant links:

Continue reading "New Draft of ECMAScript 4 Edition Grammar Released" »

March 30, 2008

Proper Tail Calls Dropped from ECMAScript 4th Edition

Brendan Eich reports that the Proper Tail Calls proposal for ECMAScript 4th Edition has been dropped. Brendan mentioned in a posting to the ES4-Discuss list yesterday that the proposal was dropped at the committee meeting last Friday:

"...(news flash) proper tail calls are out of ES4 as of yesterday's Ecma TC39 meeting, by general (regretful, in Mozilla's case) agreement."

It's not in the meeting notes yet, but I'm sure it will be added before the meeting notes are finalized. I guess the writing was on the wall, because the only three companies that have commented on this feature have all marked this feature as a low priority in the ES4 Progress Tracking Spreadsheet.

March 12, 2008

ECMAScript 4 Edition Progress Spreadsheet

John Resig, Mozilla's JavaScript Evangelist and creator of jQuery, has created a spreadsheet to track the progress of the various implementations of ECMAScript 4th Edition. There are about a half-dozen implementations in development, including the reference implementation that the ECMAScript working group is developing. Here's a brief description of the implementations so that you know what's what when you take a gander at the spreadsheet:

Continue reading "ECMAScript 4 Edition Progress Spreadsheet" »

March 07, 2008

Proposed ... (splat) operator in ECMAScript 4th Edition allows easy pass-through of rest arguments to super constructor.

Recently, Brendan Eich added a new trac ticket that proposes a new operator, ... (informally called "splat"), for ECMAScript 4th edition. The fate of this ticket is currently unknown, but I really like this proposal because it solves a thorny issue I've had when trying to pass ...rest arguments to a super constructor in ActionScript 3.0. I'll get back to that problem in a minute, but first I want to draw a clear distinction between the proposed ... (splat) operator and the ... (rest) parameter that many of you have probably used in ActionScript 3.0.

Continue reading "Proposed ... (splat) operator in ECMAScript 4th Edition allows easy pass-through of rest arguments to super constructor. " »

March 03, 2008

ECMAScript 4th Edition Vectors Proposal Draft 1

Lars T. Hansen, a computer scientist here at Adobe and the editor of the ECMAScript 4th Edition Specification, has written an initial rough draft of the Vectors proposal. The entire draft is reproduced below from his post on the ES4-Discuss list. I'm reproducing it in its entirety because the discussion list archive converts the file such that you see the raw HTML, which can be a little hard to read. If you have comments, please join the ES4-Discuss list and join in the conversation. Comments on this blog are always welcome, but to get the attention of the ES4 decision makers, you need to join the ES4-discuss list and post your comments there. Here's the link to the draft proposal:

February 19, 2008

ECMAScript 4th edition Reference Implementation M2

Last week the ES4 working group released a new version of the ES4 reference implementation (RI). The new build, M2 (for Milestone 2), replaces the M1 build that was posted back in November 2007. Today, one of the most active implementors of the RI, Graydon Hoare of Mozilla, posted a detailed "punch list" of all the proposed features that are either included or not included in the latest version of the RI.

Continue reading "ECMAScript 4th edition Reference Implementation M2" »

February 13, 2008

Vectors in ECMAScript 4

A new built-in class named Vector is proposed for ECMAScript edition 4. This class is similar to the Array class, but is designed for better performance, efficiency and error checking. Some interesting aspects of the Vector class:

  • vectors are dense;
  • vectors do bounds checking;
  • vectors can be fixed length;
  • vectors have type parameters;
  • vectors have the same methods as arrays.

Continue reading "Vectors in ECMAScript 4" »

February 07, 2008

Logical Assignment Operators

Thought I'd switch gears this week and talk about Logical Assignment Operators (||=, &&=), a feature that is proposed for ECMAScript 4th edition, but is already implemented in ActionScript 3.0. To understand the rationale behind the Logical Assignment Operators, you need to understand how the logical operators in ECMAScript and ActionScript work. Most people think of these operators in purely boolean terms. In other words, if you have two boolean variables, conditionA and conditionB, you can use the logical operators to calculate logical results. For example, if one condition is true and the other is false, the logical AND operator returns a value of false because both conditions have to be true in order for logical AND to return true.

Continue reading "Logical Assignment Operators" »

February 01, 2008

Proper Tail Calls and State Machines

It turns out that Proper Tail Calls (PTC) are handy if you want to create a simple "state machine" or "finite state machine" (See my previous post if you don't know what PTC is). A state machine is a way to create a model for the way an object behaves. For example, let's create a state machine model for a United States traffic light. First I'll use a design pattern to create one, then I'll show you a completely different approach using PTC. Here are the components of the model:

  • Finite number of states. There are three states in our example: red, yellow, and green.
  • Input. This is an event-driven model, so the input is an event that signifies a light change.
  • Finite number of transitions. There are three transitions in our example: red to green, green to yellow, and yellow to red.

Continue reading "Proper Tail Calls and State Machines" »

January 30, 2008

Proper Tail Calls and Recursion

Today I'm going to talk about the proposed Proper Tail Calls (PTC) feature and recursion. I'm going to show you how PTC can significantly reduce stack usage for functions with recursive calls in tail position. If you recall, I mentioned in my previous post that Proper Tail Calls is also called Proper Tail Recursion. This is because PTC has a significant effect on certain types of recursive functions. In case you're unfamiliar with recursion, a recursive function is a function that calls itself. For example, we could use a recursive function to calculate the factorial of a number, which means multiplying a number by every integer between that number and zero, as in 3! = 3 x 2 x 1 = 6.

Continue reading "Proper Tail Calls and Recursion" »

January 28, 2008

Proper Tail Calls, a definition

One of the things I get to do here at Adobe is help out with the drafting of the ECMAScript Edition 4 (ES4) language specification. Lately, there has been a flurry of discussion on the ES4-discuss list about one of the proposed new features, Proper Tail Calls (a.k.a. Proper Tail Recursion, but I'm going to call it PTC from now on). I thought this might give me a good opportunity to provide some background information about this feature and what it might mean for ActionScript developers in the future.

In case you don't know, ECMAScript is the language standard upon which JavaScript, JScript, ActionScript and many other languages are based. The current version of ECMAScript is the third edition, but a lot of work is going on for the fourth edition. So what I'm discussing here is not currently in ActionScript, but may one day be if PTC makes it into the fourth edition specification.

Continue reading "Proper Tail Calls, a definition" »