About ECMAScript
C-like syntax
ECMAScript's familiar syntax means that common programming idioms from other popular programming languages are available and predictable.
for (i = 0; i < a.length; i++) { if (a[i] == x) return i; }
Object-oriented programming
ECMAScript supports object-oriented programming - most values are objects with callable methods.
"hello".toUpperCase()
Functions are objects, too!
ECMAScript functions are objects and can be stored as values, passed as arguments, and returned as results. This powerful idiom from functional programming allows your functions and methods to import functionality from their caller in a simple and flexible way.
var recent = posts.sort(function(a, b) { return (a.date > b.date ? -1 : 1); }).slice(0, 10);
Objects have prototypes
Inspired by the Self programming language, ECMAScript objects inherit properties from prototype objects. Prototype-based programming facilitates easy delegation and flexible overriding of object behavior.
var orig = ListView.prototype.onclick; Widget.prototype.onclick = function(event) { logger.log('Widget', 'onclick', event); orig(event); }
Convenient data constructors
ECMAScript comes with many shorthands for common datatypes, which saves you time and makes your programs much more readable.
Arrays
var digits = [3, 1, 4, 1, 5, 9]
Objects
var img = { width: 320, height: 160, src: "images/es.png" }
Regular Expressions
var email = /([^@]*)@([^@]*)/
XML
var head = <head><title>My Page</title></head>
(XML syntax requires optional E4X support.)
Native JSON support
JSON is a popular lightweight data interchange format for interactive web pages and web services. Better yet, its syntax is a subset of ECMAScript! This means that ECMAScript offers unparalleled convenience for working with JSON data.
What's next?
The TC39 committee is actively working on the future of ECMAScript. Some of the proposals under discussion include:
- Name and property control
- Decimal arithmetic
- Classes and interfaces
- Optional type annotations
- Iterators and generators
- Destructuring binding and assignment
- Improved lexical scoping
- And more... find out more about the development of ECMAScript