What is EcmaScript?
History of EcmaScript
But, EcmaScript stuck at ES3 since 1999. Because Fourth Edition was abandoned, due to political differences concerning language complexity. Many features proposed for the Fourth Edition have been completely dropped.
In December 2009, the fifth edition was published. On the basis of ES3, ES5 assimilates some features of the popular frameworks.
EcmaScript 3 VS EcmaScript 5
There are 6 main differences between ES3 and ES5 – Implementation, properties and attributes, function, array, JSON and strict mode.
This chart from EcmaScript Wikipedia shows the application implementation in ES3 and ES5.
Properties and Attributes
ES3 code can only create properties that are writable, enumerable, and deletable. There’re only 3 property attributes in ES3 – ReadOnly, DontEnum and DontDelete. Also, ES3 can’t create properties which compute on assignment or reading.
In ES5, attributes are changed into Writable(does assignment work?), Enumerable(does for-in see it?) and Configurable(can its shape change?) and they are controllable. Attribute values are programmatically settable and testable. Also, Accessor Properties (getter/setter) was added to ES5. Property attribute control and accessor properties means it is able to emulate DOM API in ES code now.
We can manipulate properties and attributes by using ES5 methods. For example, we can use Object.defineProperty(obj, propName, propDescriptor) to define a property as well as modify property attributes.
Define a property:
Modify property attributes:
These are other object meta methods:
• Object.defineProperties(obj, propName, descriptorSet)
• Object.create(protoObj, descriptorSet)
The function in ES5 has 4 features:
1. the value of ‘this’ will not be changed when calling ‘.call()’ or ‘.apply()’
2. ‘null’ and ‘undefined’ will not be returned to global
3. a non-object will not be switched to an object
4. new method Bind. This bind method allows the user to set up the value of this and apply the value to the function.
In ES3, there’re not many methods can be used to manipulate the array. ES5 enhances this, now all these methods are all can be used directly.
These are array meta methods:
There is no normative technology of translating JSON data in ES3. In ES5, two main libraries were added to support for JSON. JSON.stringify() will return the value to JSON String, JSON.parse() will do the opposite.
JSON.stringify() → string
JSON.parse() → value
In ES3 or ES5-nonstrict, Failure is silent. Execution will proceed assuming success. And we can’t check after every assignment to see if it succeeded. In ES5, Failed assignments throw. A subset intended to provide more thorough error checking and avoid error-prone constructs.
This is how we use strict mode:
On the basis of ES3, ES5 assimilates some features of the popular frameworks and enhances its capability. It’s better for real programs.
EcmaScript From Wikipedia
Intensive Study of EcmaScript 5
EcmaScript 3.1 Object model