ECMAScript 4: The missing version
In your build tools, you may have noticed that you have an ECMAScript 3 target, and 5 and up, but never a 4. Why is that?
I thought it would be fun to dive into ECMAScript 4 a bit and see what we didn’t get.
A brief history
According to Wikipedia, the first draft of ECMAScript 4 was dated February 1999. The original target for completion was August 2008.
ECMAScript 4 was very ambitious, and added a ton of features that were percieved as important and missing from ECMAScript 3. It also ‘fixed’ a number of things in the previous version, making it backwards incompatible in various ways.
ES4 was met with a bunch of controversies, and lacked sufficient support from browser vendors to be released and was ultimately abandoned.
In 2008 the standard was pronounced dead, and ES3.1 was renamed to ES5, which was a much more conservative and incremental update to ECMAScript.
The closest thing we had for ES4, was probably Flash Actionscript 3. There was a point during the release of AS3 that some of us thought that Flash and the Web was eventually going to converge.
For more details on politics and history of ES4, check out this great article on the auth0 blog.
What could have been?
Classes
Classes eventually landed in ES6, but here’s how it might have looked like earlier:
class C {
var val
var number = 500;
const pi = 3.14
// A function
function f(n) { return n+val*2 }
// Getters and setters
function set foo(n) {
val = n;
}
function get foo() {
return val;
}
}
The syntax here is pretty different, but another notable is that these classes had properties and constants. Field declarations are currently ‘experimental’, so we almost caught up here.
Another surprising thing is that there is no this
. Instead of variables being
global by default, ES4 would first look in the class scope before checking higher
scopes.
ES4 also had the following keywords for class members:
static
final
private
,protected
,public
.prototype
, to define class members on its prototype. Not sure what the use-case is, but it’s there.
Interfaces
ES4 introduced interfaces, which is something we don’t have today (unless you use Typescript):
interface MyInterface {
function foo();
}
Strict typing
ES4 introduced strict typing:
Truncated by Planet PHP, read more at the original (another 11730 bytes)