an overview of java script in 2015 (ecma script 6)

Post on 15-Jul-2015

104 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

An Overview of JavaScript in 2015 (ECMAScript 6)

Language Features

This sixth edition of JavaScript introduces a lot of new language syntax features, it might even be the most feature packed revision to date in terms of language additions, and that is with some of the features scheduled, like comprehensions and rest and spread properties being delayed to the next edition.

These features are also backwards compatible, in the sense that they are mostly syntactic sugar and can be desugared to older versions of the language, meaning we can use them right now with a source to source compiler (otherwise known as a transpiler).

Arrow Functions(1)

Arrow functions are a function shorthand using the => syntax.

However, unlike normal functions however, arrows share the same lexical this as their surrounding code.

Arrow Functions(2)

expression

Binary and Octal Literals(1)

Binary and Octal literals are new forms of numeric literals added for binary and octal numbers, denoted by b and o respectively.

Binary and Octal Literals(2)

Block Scoping

Block scoping are new forms of declaration for defining variables scoped to a single block, as opposed to variables declared with varwhich have a function-level scope.

Let

Const

Block Scoping-Let(1)

We can use let in-place of var to define block-local variables without having to worry about them clashing with variables defined elsewhere within the same function body.

Block Scoping-Let(2)

Block Scoping-Const(1)

const follows the same rules as let, except that the value is immutable so we can only assign to it once.

Block Scoping-Const(2)

Classes(1) Classes are a concise declarative syntax for writing object oriented

prototype patterns with a classical classes approach, the class syntax has support for inheritance, super calls, instance and static properties and constructors.

Classes(2)

Classes(3)

Default Parameter Values(1)

Default parameter values allows us to initialize parameters when they were not explicitly provided. Where-as previously we would often check for undefined and assign default values.

Default Parameter Values(2)

DestructuringAssignments(1)

Destructuring assignment allows us to assign parts of an object to several variables at once.

DestructuringAssignments(2)

Iterators(1)

Iterators allow iteration over arbitrary objects, while this by itself is not strictly a language feature, rather a protocol/pattern that is implemented by the core library, it does tie into other language features such as generators and for-for which work with this pattern.

The iterator protocol takes the following form, any object can be an iterator as long as it defines a next() method.

Any object can be iterable as long as it defines an iterator method, the named of the method is obtained through Symbol.iterator, often denoted with @@iterator.

Iterators(2)

Iterators-For Of(1)

The for-of loop allows you to conveniently loop over iterableobjects.

Iterators-For Of(2)

Generators(1) Generators make it easy to create iterators. Instead of tracking

state yourself and implementing iterator, you just use yield (or yield* to yield each element in an iterator).

Generators(2)

Method Definition Shorthand(1)

Method Definition Shorthand is a shorthand syntax for method definitions in object initializers, whereas before we would explicitly state the property name.

Method Definition Shorthand(2)

Property Value Shorthand(1)

Property Value Shorthand is a shorthand syntax object initializers whose property keys are initialized by variables of the same name, whereas before we would have to repeat the property key and variable name.

Property Value Shorthand(2)

Rest Parameters(1)

Rest parameters provides a cleaner way of dealing with variadicfunctions, that is functions that take a arbitrary number of parameters.

Rest Parameters(2)

Spread Operator(1)

The spread operator allows an expression to be expanded in places where multiple arguments or multiple elements are expected.

Spread Operator(2)

Template Strings(1)

Template strings are a new form of string literals using backticks, they are multiline and support interpolation through the ${} syntax.

Template strings can also be in the form of tagged template strings, allowing us to prefix the literal with a tag. Tags are basically filtering functions that can perform substitutions and string manipulation.

Template Strings(2)

Reference http://caspervonb.com/javascript/an-overview-of-javascript-in-

2015-ecmascript-6/

https://google.github.io/traceur-compiler/demo/repl.html

top related