JS: ECMAScript 2015
Over 10 major features are added to the language, effectively making JavaScript a new language.
Here is a quick overview of new features.
let
let is like var , but with a clean block-level scope.
const
const is similar to let, except you can't change its value once set.
Arrow Function
you can write function like this
((x, y) => { return x + y; });
but no this (binding) , and no arguments Object, no Function Name Hoisting .
Function Argument Default Values
function parameter can specify a default value.
Rest Parameters
function can now specify to take any number of parameters, by syntax ...args
Destructuring Assignment
// destructuring assignment let [x, y, z] = [3, 4, 6];
Object Literal Expression, Computed Property Keys
new syntax for object literal to have computed property key by an expression.
obj = {[expression]:value}
Object Literal Expression, Method Definition Shorthand
new syntax shorthand for defining methods in object literal expression.
obj = {
method_name() {body},
etc
};
__proto__
Allow the use of property key __proto__
to get/set parent.
Template String
allows you to embed variable or expression in a string, or have newline char.
Spread Operator
The spread operator is 3 dots followed by a array, like this: ...xArray. What it does is effectively remove the bracket of the array.
for-of Loop
lets you properly loop thru an array, or new datatypes such as set and map, or any iterable object. Iterable object is a new concept, created just for for-of loops.
Interface, Iterable, Iterator, Generator
Iterable is new. It is a array like thing but items are generated at time it is used.
array is made iterable.
iterator is created to support iterable.
for-of loop and spread operator works with iterables.
these are created to support iterable.
- JS: Interface
- Iterator prototype
- JS: Generator
Generator Function is created to support creating iterable.
Set Object
Set object lets you have a data structure of set. That is, a collection of unique values.
Map Object
Map object lets you have a data structure of key value pairs. Similar to JavaScript Object, but now designed to be used as a data structure. For example, keys can be any type, not just string.
Reflect
The Reflect object is used as namespace to host a group
of static functions. Reflect methods typically duplicate operator behavior
in function form, or provides a more strict or improved version of existing
methods.
Class
class is a new keyword that lets you conveniently define object and its prototype.
New keywords are:
class,
constructor,
static,
extends,
super.
regex
New regex flag "u". For unicode. Treat string as sequence of unicode characters.
New regex flag "y". For “sticky”. This means next regex match call will start with lastIndex.
New value properties.
RegExp.prototype.flagsRegExp.prototype.stickyRegExp.prototype.unicode
New function properties.
RegExp.prototype [ Symbol.match ](str)RegExp.prototype [ Symbol.replace ](str, replace)RegExp.prototype [ Symbol.search ](str)RegExp.prototype [ Symbol.split ](str, limit)
New Array Properties
new array constructor properties
- convert array-like and iterable to array.
- JS: Array.from
- functional form of literal expression for array
- JS: Array.of
new array prototype properties
- JS: Array.prototype.copyWithin
- JS: Array.prototype.fill
- JS: Array.prototype.find
- JS: Array.prototype.findIndex
- JS: Array.prototype.entries
- JS: Array.prototype.keys
- JS: Array.prototype.values
Array.prototype[Symbol.iterator](same as Array.prototype.values)Array.prototype[Symbol.unscopables]
New String Properties
static methods
string methods
String.prototype.localeCompareString.prototype.normalizeString.prototype[Symbol.iterator]
New Object Methods
New Function Properties
function property "name"
New Number Properties
- JS: Number.isFinite
- JS: Number.isInteger
- JS: Number.isNaN
- JS: Number.isSafeInteger
- JS: Number.parseFloat (String to Number)
- JS: Number.parseInt (String to Number)
Number.EPSILONNumber.MIN_SAFE_INTEGERNumber.MAX_SAFE_INTEGER
new Math methods
Math[Symbol.toStringTag]Math.signMath.froundMath.truncMath.cbrtMath.expm1Math.log1pMath.log10Math.log2Math.hypotMath.sinhMath.coshMath.tanhMath.asinhMath.acoshMath.atanhMath.clz32Math.imul
html-like comments
formally recognize html comment.
block-level function declaration
now allow function declaration inside a block.
// es2015 block-level function declaration function f() { function g(x) { return x + 1; } return g(1); } console.log(f()); // 2
Module, Keyword “import”, “export”
Unicode Escape Syntax
Now you can escape unicode by
\u{4_to_6_hex_digits}
Octal and binary literals
// octal notation console.log( 0o10 ) // 8 // binary console.log( 0b10 ) // 2
new.target
Promise
- String static methods
- String.prototype methods
- RegExp.prototype properties
Subclassing
- Array is subclassable
- RegExp is subclassable
- Function is subclassable
- Promise is subclassable
- miscellaneous subclassables
Misc
- prototype of bound functions
- Object static methods accept primitives
- own property order
- miscellaneous
Annex b
- Object.prototype.__proto__
- hoisted block-level function declaration
- String.prototype HTML methods
- RegExp.prototype.compile
ArrayBuffer
ECMAScript 2015 §Structured Data#sec-arraybuffer-objects