A better JavaScript! ECMAScript 5 was standardized in late 2009 but only recently has it has started showing up in browsers.
It supersedes the 3rd edition, which was ratified in 1999. This is in IE 9+.
ECMAScript 5 has actually two modes
- ES5/Default
- ES5/Strict – Switching to strict mode requires the statement shown to be placed at the start of a file or function. — ‘use strict’;
Future versions are going to be built on top of ES5/Strict and it is recommended that the default version be avoided.
Douglas Crockford goes through what the features are, what can be used right now and what your kids will be able to use: http://channel9.msdn.com/events/MIX/MIX11/EXT13
Some features:
- Can use trailing commas: { “trailing”: “comma”, } or [ “trailing”, “comma”, ]
- Constants – Infinity, NaN
- parseInt works! parseInt(‘08’) === 8
- JSON.parse(text, reviver) & JSON.stringify(value, replacer, space)
- Function.prototype.bind added
- String.prototype.trim added
- Array.prototype.every added
- Array.isArray()
- get/set: These are the getter and setter functions needed for accessor properties
- Object.keys (much better than for-in)!
- Object.create
- Attributes – Value, Writable, Enumerable, Configurable, Get, Set
- Can limit the object extensibility which can make the object immutable.
- Strict mode
- Reserved words: implements, intereface, let, package, private, protected, etc.
- No more implied glabal variables within functions
- “this” is not bound to the global object by function form.