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

35
An Overview of JavaScript in 2015 (ECMAScript 6)

Upload: learningtech

Post on 15-Jul-2015

106 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: An overview of java script in 2015 (ecma script 6)

An Overview of JavaScript in 2015 (ECMAScript 6)

Page 2: An overview of java script in 2015 (ecma script 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).

Page 3: An overview of java script in 2015 (ecma script 6)

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.

Page 4: An overview of java script in 2015 (ecma script 6)

Arrow Functions(2)

expression

Page 5: An overview of java script in 2015 (ecma script 6)

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.

Page 6: An overview of java script in 2015 (ecma script 6)

Binary and Octal Literals(2)

Page 7: An overview of java script in 2015 (ecma script 6)

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

Page 8: An overview of java script in 2015 (ecma script 6)

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.

Page 9: An overview of java script in 2015 (ecma script 6)

Block Scoping-Let(2)

Page 10: An overview of java script in 2015 (ecma script 6)

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.

Page 11: An overview of java script in 2015 (ecma script 6)

Block Scoping-Const(2)

Page 12: An overview of java script in 2015 (ecma script 6)

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.

Page 13: An overview of java script in 2015 (ecma script 6)

Classes(2)

Page 14: An overview of java script in 2015 (ecma script 6)

Classes(3)

Page 15: An overview of java script in 2015 (ecma script 6)

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.

Page 16: An overview of java script in 2015 (ecma script 6)

Default Parameter Values(2)

Page 17: An overview of java script in 2015 (ecma script 6)

DestructuringAssignments(1)

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

Page 18: An overview of java script in 2015 (ecma script 6)

DestructuringAssignments(2)

Page 19: An overview of java script in 2015 (ecma script 6)

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.

Page 20: An overview of java script in 2015 (ecma script 6)

Iterators(2)

Page 21: An overview of java script in 2015 (ecma script 6)

Iterators-For Of(1)

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

Page 22: An overview of java script in 2015 (ecma script 6)

Iterators-For Of(2)

Page 23: An overview of java script in 2015 (ecma script 6)

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).

Page 24: An overview of java script in 2015 (ecma script 6)

Generators(2)

Page 25: An overview of java script in 2015 (ecma script 6)

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.

Page 26: An overview of java script in 2015 (ecma script 6)

Method Definition Shorthand(2)

Page 27: An overview of java script in 2015 (ecma script 6)

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.

Page 28: An overview of java script in 2015 (ecma script 6)

Property Value Shorthand(2)

Page 29: An overview of java script in 2015 (ecma script 6)

Rest Parameters(1)

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

Page 30: An overview of java script in 2015 (ecma script 6)

Rest Parameters(2)

Page 31: An overview of java script in 2015 (ecma script 6)

Spread Operator(1)

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

Page 32: An overview of java script in 2015 (ecma script 6)

Spread Operator(2)

Page 33: An overview of java script in 2015 (ecma script 6)

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.

Page 34: An overview of java script in 2015 (ecma script 6)

Template Strings(2)

Page 35: An overview of java script in 2015 (ecma script 6)

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

2015-ecmascript-6/

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