SlideShare ist ein Scribd-Unternehmen logo
1 von 31
ECMAScript 6
Getting Started with ES6
http://goo.gl/OuwX9t
Nitay Neeman
⚬ What is ECMAScript 6?
⚬ Brief history
⚬ A lot of new features
⚬ Conclusions
We will talk about
ECMAScript 6 is new standard of ECMA International.
Scheduled to be released on June 2015.
The project name is Harmony.
What is ES6?
ECMAScript is a standard of scripting languages.
Actually, it is the syntax.
JavaScript is an implementation of standard by specific
browsers.
There are many others implementations:
JScript, ActionScript, Ejscript, Objective-J, Nashorn…
All those very similar and depend on the application
that executes them.
Differences between ES & JS
⚬ 1995 - LiveScript was born by Brendan Eich of Netscape (in 10
days!).
In the end of year, the name changed to JavaScript in order to
attract Java developers.
⚬ 1996 - Microsoft came and copied JavaScript for supporting of IE.
It was called JScript. Meanwhile, JavaScript was delivered to ECMA
International in purpose to be a standard of scripting languages.
⚬ 1997 - JavaScript was adopted by ECMA as ECMA-262 standard.
⚬ 1999 - Main version was ECMAScript 3.
Until this version, everything was fine...
Brief History
⚬ 2000 ~ 2007 - ECMAScript 4 planned to provide a lot of complex
features. Microsoft, Yahoo & Google refused and started to develop
ECMAScript 3.1.
⚬ 2008 - Brendan Eich was back and announced that Ecma TC39
would focus work on the ECMAScript 3.1.
It was decided:
1. ECMAScript 3.1 will rename to ECMAScript 5.
2. ECMAScript 4 will rename to ECMAScript 6.
⚬ 2009 - ECMAScript 5 was published.
⚬ 2015 - ECMAScript 6 will be published.
Brief History
Cool history, but.. I WANT CODE!
A new and short way to create an anonymous function.
Arrow function created to be more semantic and readable.
Example of using:
Important issues:
⚬ It is not newable (will throw an error when you try..)
⚬ It can be used in expressions and in statements.
⚬ Fixed ‘this’ issue!
Arrows
var square = x => x * x;
The following code will not work (‘this’ will be the Window object):
Arrows - The meaning of ‘this’ issue
var timer = function () {
this.seconds = 0;
this.printSeconds = function () {
console.log(this.seconds);
};
setInterval(function () {
this.seconds++; // We cannot call to seconds field here
this.printSeconds(); // We cannot call to printSeconds here
}, 1000);
};
var myTimerInstance = new timer();
The solution based on arrow function:
Arrows - The meaning of ‘this’ issue
var fixedTimer = function () {
this.seconds = 0;
this.printSeconds = () => console.log(this.seconds);
setInterval(() => {
this.seconds++;
this.printSeconds();
}, 1000);
};
var myFixedTimerInstance = new fixedTimer();
Block-level Scope
Until now, all the variables was global. Blame the hoisting.
function getMyValueByCondition(condition) {
// myValue will be declared here and will set to be undefined.
if (condition) {
var myValue = "My Value";
return myValue;
} else {
// myValue will be undefined here.
}
// myValue will be undefined here.
}
Block-level Scope - let
Now, we can create a local variable by ‘let’ keyword!
let enables to block scoping.
Important issues:
⚬ Only one declaration in each scope (or you will get a syntax error).
⚬ Therefore, It is unusual to use let in the global scope.
⚬ Very useful for loops!
Example of using:
let x = 100;
var x = 'String'; // A syntax error will appear
Block-level Scope - const
Similar to ‘let’ keyword, we can declare now on a constants!
The keyword is ‘const’.
Important to note that:
⚬ Constant must be initialized once, and it cannot be changed.
⚬ Constant is a valid only for the current scope! (just like ‘let’).
Example of using:
const PI = 3.1415926536;
PI = 0; // A syntax error will appear
Default parameters allow parameters to be initialized with default values.
That is - the value will be defaulted in a case of:
⚬ No value was passed.
⚬ Undefined was passed.
Default Parameters
function getRoot(number, root = 2) {
return Math.pow(number, 1 / root);
}
// getRoot(49) will be 7.
// getRoot(8,3) will be 2.
Template Strings is a new syntax for the old strings.
It deals with the following problems:
⚬ Supporting in multiline strings has never been before.
⚬ Ability to separate parts of the string for values in variables.
⚬ Transformation of a string into html is not really safe.
Template Strings solve all those issues.
The syntax is very simple, and marked by backticks ( ` ).
Template Strings
let templateString = `Hello
World!`;
We can use substitutions on Template Strings:
Also, we can use tags on Template Strings:
Template Strings - Substitutions & Tags
let degrees = 90;
let templateString = `Conversion of 90 degrees into radians is: ${(degrees * Math.PI) / 180}`;
let printOfResultOnly = function (str, degrees, result) {
// str will be ["Conversion of ", " degrees into radians is:", ""]
return result;
};
templateString = printOfResultOnly`Conversion: ${degrees} degrees into radians is: ${(degrees
* Math.PI) / 180}`;
Classes are a better syntax over the prototype object.
What we will get in the bundle?
⚬ Creation of instances via ‘new’ keyword.
⚬ Encapsulating fields and functions that relevant the class.
⚬ Intuitive constructor is exist.
⚬ Even extend and override a methods!
⚬ Defining of static members.
⚬ Note that we cannot define private members.
Classes
class Animal {
constructor(age = 0) {
this.age = age;
}
eat() {}
}
Example of inheritance:
Classes
class Cat extends Animal {
constructor(age, name) {
super(age);
this.name = name;
}
eat() {
return `I am ${this.name}, and i love milk!`;
}
}
let kitty = new Cat(5, 'Kitty');
Until now, were two main approaches for modules:
⚬ CommonJS - Compact API that designed for synchronized loading.
It focuses in the server side.
Motivation: Simple and clear syntax.
Main Implementations: Node.js, RingoJS.
⚬ Asynchronous Module Definition - More complex API that designed for
asynchronous loading.
It focuses in the client side.
Motivation: Dependency management.
Main Implementation: RequireJS.
Modules
Modules are even more simple than CommonJS together with the
supporting in asynchronous loading of AMD!
There are two new keywords: export and import.
Example of using:
Modules
// math.js
export const PI = Math.PI;
export function square(x) {
return x*x;
}
// app.js
import {PI, square} from 'math'; // Alternatively, could be: import * as math from ‘math’
console.log(square(PI)); // Will be PI^2
Rest parameters is a better alternative to arguments.
The rest parameter is an array that marked by ‘...’ (three points).
All parameters that will be delivered from this location, will be in this array.
Example of using:
Rest Parameters
let myFunction = function(x, ...parametersThatIDontCare) {
// parametersThatIDontCare = [true, 'Cool String']
return x * parametersThatIDontCare.length;
};
myFunction(10, true, 'Cool String'); // Will be 20
Spread operator allows to deliver an array, and separate it to multiple
parameters in the declaration of function.
It should be inverse of rest parameters.
Example of using:
Spread Operator
let myFunction = function(str, x, y, z) {
return str + (x+y+z);
};
myFunction('The sum is:', ...[1, 10, 100]);
Destructuring is way to select a specific arguments from array or object
into variables. Actually, destructuring is matching between two collections
by different patterns.
Example of using:
Destructuring
let [a, , , b] = [1, 3, 5, 9];
console.log('a + b is: ' + (a + b)); // Will be 10
let { one, two, three: [, threeValue] } = {
one: 1,
two: 2,
three: [4, 3]
};
console.log('one + two + three is: ' + (one + two + threeValue)); // Will be 6
let [d, c] = [c, d]; // Swap the values without temp!
Symbol is new primitive type that used as private reference to property.
Symbols are unique!
The file must hold this symbol to access the property of object.
Example of using:
Symbols
var privateProperty = Symbol('Description: Private property');
var object = {};
object[privateProperty] = 'My Private';
console.log(privateProperty); // Is a symbol
console.log(object[privateProperty]); // Will print 'My Private'
Map is dictionary data structure that stores pairs of key and value.
Difference from object, now the key can be an object!
Map provides an API with: set, get, clear, forEach, size, and more!
Example of using:
Maps
let objectKey = {value: 100};
let map = new Map();
map.set('stringKey', 'The value is ');
map.set(objectKey, objectKey.value);
console.log(map.get('stringKey') + map.get(objectKey)); // Will be 'The value is 100'
console.log('Map size: ' + map.size); // Will be 2
Set is data structure of collection of values.
It wraps the old object with better API.
It provides an API with: add, has, clear, forEach, size, and more!
Example of using:
Sets
let mySetList = new Set();
mySetList.add('First').add('Second');
mySetList.add(true);
console.log(mySetList); // Will be {"First", "Second", true}
console.log(mySetList.has('Second')); // Will be true
Along all main features, little changes in numbers were made.
Until now, the methods isFinite and isNaN could get numbers as string:
Now, we have those methods in part of Number,
which will accept only numbers values:
Little changes of Numbers
console.log(isFinite("1")); // Will be true
console.log(isNaN("NaN")); // Will be true
console.log(Number.isFinite("1")); // Will be false
console.log(Number.isNaN("NaN")); // Will be false
Added function to identify if it is an integer!
Added a lot of new Math methods!
For example:
⚬ Math.acosh(x), Math.asinh(x), Math.atanh(x)
⚬ Math.log1p(x), Math.log10(x), Math.log2(x)
⚬ Math.trunc(x)
Little changes of Numbers
console.log(Number.isInteger(25.5)); // Will be false
⚬ Object.observe - Allows to register to changes of data model by
callback (Feature of ES7).
⚬ Promises - Asynchronous operations.
⚬ Generators - Special functions that creates a type of iterators.
⚬ Proxies - Creating a proxy on a particular object allows a predefined
handler to get notified when something happens.
⚬ Array comprehensions - Syntax that allows you to quickly assemble a
new array based on an existing one (Feature of ES7).
⚬ Tail call optimization - Instead of create new stack frames, It reuses old
stack frames.
Unspoken features
⚬ ECMAScript 6 standard of scripting languages.
⚬ ECMAScript 6 will be published on June 2015.
⚬ ECMAScript 6 will bring a lot of changes:
○ Arrows
○ let & const
○ Default parameters, Rest Parameters
○ Spread Operator
○ Template Strings
○ Classes & Modules
○ Destructuring
○ Symbols
○ Maps & Sets
○ Minor changes of Numbers
Conclusions
Questions
?

Weitere ähnliche Inhalte

Was ist angesagt?

ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMMario Fusco
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013aleks-f
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Leonardo Borges
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Leonardo Borges
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingMario Fusco
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
purely_functional_play_framework_application
purely_functional_play_framework_applicationpurely_functional_play_framework_application
purely_functional_play_framework_applicationNaoki Aoyama
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in SwiftNetguru
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript FunctionsBrian Moschel
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskellnebuta
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Functionxxbeta
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerMario Fusco
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is hereSebastiano Armeli
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012aleks-f
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 
C++totural file
C++totural fileC++totural file
C++totural filehalaisumit
 

Was ist angesagt? (20)

ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
purely_functional_play_framework_application
purely_functional_play_framework_applicationpurely_functional_play_framework_application
purely_functional_play_framework_application
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in Swift
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Function
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
C++totural file
C++totural fileC++totural file
C++totural file
 

Andere mochten auch

What is New in HTML5?
What is New in HTML5?What is New in HTML5?
What is New in HTML5?Nitay Neeman
 
Mwr twr white-paper
Mwr twr white-paperMwr twr white-paper
Mwr twr white-paperAdarsh Sinha
 
14001 Certificate_Md. Sajjad Hossain Sajib
14001 Certificate_Md. Sajjad Hossain Sajib14001 Certificate_Md. Sajjad Hossain Sajib
14001 Certificate_Md. Sajjad Hossain SajibSajjad Sajib
 
TDC2016SP - Rails Custom Validators - Não se esqueça deles
TDC2016SP - Rails Custom Validators - Não se esqueça delesTDC2016SP - Rails Custom Validators - Não se esqueça deles
TDC2016SP - Rails Custom Validators - Não se esqueça delestdc-globalcode
 
Jharkhand Staff Selection Commission notification 2015
Jharkhand Staff Selection Commission notification 2015Jharkhand Staff Selection Commission notification 2015
Jharkhand Staff Selection Commission notification 2015Raja Kashyap
 
Cinco características para franquiciar una empresa.
Cinco características para franquiciar una empresa.Cinco características para franquiciar una empresa.
Cinco características para franquiciar una empresa.bomboclank
 
Estructura de un computador
Estructura de un computadorEstructura de un computador
Estructura de un computadorArroyoEric
 
MAS Decadence Presentation
MAS Decadence PresentationMAS Decadence Presentation
MAS Decadence Presentationlatymermedia
 
Capitulo 3 y 4 del libro blanco de las tic
Capitulo 3 y 4 del libro blanco de las ticCapitulo 3 y 4 del libro blanco de las tic
Capitulo 3 y 4 del libro blanco de las ticUniversidad del QuindÍo
 
Пан Коцький
Пан КоцькийПан Коцький
Пан КоцькийOsya Dubyaga
 
Why do we need TypeScript?
Why do we need TypeScript?Why do we need TypeScript?
Why do we need TypeScript?Nitay Neeman
 
4 ficha refuerzo 1º eso
4 ficha  refuerzo    1º   eso4 ficha  refuerzo    1º   eso
4 ficha refuerzo 1º esoLolicanadilla
 
TDC2016SP - Esqueça Grunt ou Gulp. Webpack and NPM rule them all!
TDC2016SP -  Esqueça Grunt ou Gulp. Webpack and NPM rule them all!TDC2016SP -  Esqueça Grunt ou Gulp. Webpack and NPM rule them all!
TDC2016SP - Esqueça Grunt ou Gulp. Webpack and NPM rule them all!tdc-globalcode
 
McCulley_FinalPaperAlexander
McCulley_FinalPaperAlexanderMcCulley_FinalPaperAlexander
McCulley_FinalPaperAlexanderBrent McCulley
 

Andere mochten auch (19)

What is New in HTML5?
What is New in HTML5?What is New in HTML5?
What is New in HTML5?
 
Algoritmo selectivo
Algoritmo selectivoAlgoritmo selectivo
Algoritmo selectivo
 
Mwr twr white-paper
Mwr twr white-paperMwr twr white-paper
Mwr twr white-paper
 
14001 Certificate_Md. Sajjad Hossain Sajib
14001 Certificate_Md. Sajjad Hossain Sajib14001 Certificate_Md. Sajjad Hossain Sajib
14001 Certificate_Md. Sajjad Hossain Sajib
 
TDC2016SP - Rails Custom Validators - Não se esqueça deles
TDC2016SP - Rails Custom Validators - Não se esqueça delesTDC2016SP - Rails Custom Validators - Não se esqueça deles
TDC2016SP - Rails Custom Validators - Não se esqueça deles
 
Jharkhand Staff Selection Commission notification 2015
Jharkhand Staff Selection Commission notification 2015Jharkhand Staff Selection Commission notification 2015
Jharkhand Staff Selection Commission notification 2015
 
Libro blanco de las tic capitulo 1 y 2
Libro blanco de las tic  capitulo 1 y 2Libro blanco de las tic  capitulo 1 y 2
Libro blanco de las tic capitulo 1 y 2
 
Cinco características para franquiciar una empresa.
Cinco características para franquiciar una empresa.Cinco características para franquiciar una empresa.
Cinco características para franquiciar una empresa.
 
Estructura de un computador
Estructura de un computadorEstructura de un computador
Estructura de un computador
 
MAS Decadence Presentation
MAS Decadence PresentationMAS Decadence Presentation
MAS Decadence Presentation
 
Capitulo 3 y 4 del libro blanco de las tic
Capitulo 3 y 4 del libro blanco de las ticCapitulo 3 y 4 del libro blanco de las tic
Capitulo 3 y 4 del libro blanco de las tic
 
Пан Коцький
Пан КоцькийПан Коцький
Пан Коцький
 
Why do we need TypeScript?
Why do we need TypeScript?Why do we need TypeScript?
Why do we need TypeScript?
 
4 ficha refuerzo 1º eso
4 ficha  refuerzo    1º   eso4 ficha  refuerzo    1º   eso
4 ficha refuerzo 1º eso
 
TDC2016SP - Esqueça Grunt ou Gulp. Webpack and NPM rule them all!
TDC2016SP -  Esqueça Grunt ou Gulp. Webpack and NPM rule them all!TDC2016SP -  Esqueça Grunt ou Gulp. Webpack and NPM rule them all!
TDC2016SP - Esqueça Grunt ou Gulp. Webpack and NPM rule them all!
 
Blogs Empresariales T2
Blogs Empresariales T2Blogs Empresariales T2
Blogs Empresariales T2
 
Ansoff matrix
Ansoff matrixAnsoff matrix
Ansoff matrix
 
McCulley_FinalPaperAlexander
McCulley_FinalPaperAlexanderMcCulley_FinalPaperAlexander
McCulley_FinalPaperAlexander
 
Sistema de franquicias
Sistema de franquicias Sistema de franquicias
Sistema de franquicias
 

Ähnlich wie Getting started with ES6

Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2Warui Maina
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operatorSAFFI Ud Din Ahmad
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based TestingC4Media
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderAndres Almiray
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3Mohamed Ahmed
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 

Ähnlich wie Getting started with ES6 (20)

Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
ECMAScript 2015
ECMAScript 2015ECMAScript 2015
ECMAScript 2015
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based Testing
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Linked list
Linked listLinked list
Linked list
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilder
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 

Kürzlich hochgeladen

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 

Kürzlich hochgeladen (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 

Getting started with ES6

  • 1. ECMAScript 6 Getting Started with ES6 http://goo.gl/OuwX9t Nitay Neeman
  • 2. ⚬ What is ECMAScript 6? ⚬ Brief history ⚬ A lot of new features ⚬ Conclusions We will talk about
  • 3. ECMAScript 6 is new standard of ECMA International. Scheduled to be released on June 2015. The project name is Harmony. What is ES6?
  • 4. ECMAScript is a standard of scripting languages. Actually, it is the syntax. JavaScript is an implementation of standard by specific browsers. There are many others implementations: JScript, ActionScript, Ejscript, Objective-J, Nashorn… All those very similar and depend on the application that executes them. Differences between ES & JS
  • 5. ⚬ 1995 - LiveScript was born by Brendan Eich of Netscape (in 10 days!). In the end of year, the name changed to JavaScript in order to attract Java developers. ⚬ 1996 - Microsoft came and copied JavaScript for supporting of IE. It was called JScript. Meanwhile, JavaScript was delivered to ECMA International in purpose to be a standard of scripting languages. ⚬ 1997 - JavaScript was adopted by ECMA as ECMA-262 standard. ⚬ 1999 - Main version was ECMAScript 3. Until this version, everything was fine... Brief History
  • 6. ⚬ 2000 ~ 2007 - ECMAScript 4 planned to provide a lot of complex features. Microsoft, Yahoo & Google refused and started to develop ECMAScript 3.1. ⚬ 2008 - Brendan Eich was back and announced that Ecma TC39 would focus work on the ECMAScript 3.1. It was decided: 1. ECMAScript 3.1 will rename to ECMAScript 5. 2. ECMAScript 4 will rename to ECMAScript 6. ⚬ 2009 - ECMAScript 5 was published. ⚬ 2015 - ECMAScript 6 will be published. Brief History
  • 7. Cool history, but.. I WANT CODE!
  • 8. A new and short way to create an anonymous function. Arrow function created to be more semantic and readable. Example of using: Important issues: ⚬ It is not newable (will throw an error when you try..) ⚬ It can be used in expressions and in statements. ⚬ Fixed ‘this’ issue! Arrows var square = x => x * x;
  • 9. The following code will not work (‘this’ will be the Window object): Arrows - The meaning of ‘this’ issue var timer = function () { this.seconds = 0; this.printSeconds = function () { console.log(this.seconds); }; setInterval(function () { this.seconds++; // We cannot call to seconds field here this.printSeconds(); // We cannot call to printSeconds here }, 1000); }; var myTimerInstance = new timer();
  • 10. The solution based on arrow function: Arrows - The meaning of ‘this’ issue var fixedTimer = function () { this.seconds = 0; this.printSeconds = () => console.log(this.seconds); setInterval(() => { this.seconds++; this.printSeconds(); }, 1000); }; var myFixedTimerInstance = new fixedTimer();
  • 11. Block-level Scope Until now, all the variables was global. Blame the hoisting. function getMyValueByCondition(condition) { // myValue will be declared here and will set to be undefined. if (condition) { var myValue = "My Value"; return myValue; } else { // myValue will be undefined here. } // myValue will be undefined here. }
  • 12. Block-level Scope - let Now, we can create a local variable by ‘let’ keyword! let enables to block scoping. Important issues: ⚬ Only one declaration in each scope (or you will get a syntax error). ⚬ Therefore, It is unusual to use let in the global scope. ⚬ Very useful for loops! Example of using: let x = 100; var x = 'String'; // A syntax error will appear
  • 13. Block-level Scope - const Similar to ‘let’ keyword, we can declare now on a constants! The keyword is ‘const’. Important to note that: ⚬ Constant must be initialized once, and it cannot be changed. ⚬ Constant is a valid only for the current scope! (just like ‘let’). Example of using: const PI = 3.1415926536; PI = 0; // A syntax error will appear
  • 14. Default parameters allow parameters to be initialized with default values. That is - the value will be defaulted in a case of: ⚬ No value was passed. ⚬ Undefined was passed. Default Parameters function getRoot(number, root = 2) { return Math.pow(number, 1 / root); } // getRoot(49) will be 7. // getRoot(8,3) will be 2.
  • 15. Template Strings is a new syntax for the old strings. It deals with the following problems: ⚬ Supporting in multiline strings has never been before. ⚬ Ability to separate parts of the string for values in variables. ⚬ Transformation of a string into html is not really safe. Template Strings solve all those issues. The syntax is very simple, and marked by backticks ( ` ). Template Strings let templateString = `Hello World!`;
  • 16. We can use substitutions on Template Strings: Also, we can use tags on Template Strings: Template Strings - Substitutions & Tags let degrees = 90; let templateString = `Conversion of 90 degrees into radians is: ${(degrees * Math.PI) / 180}`; let printOfResultOnly = function (str, degrees, result) { // str will be ["Conversion of ", " degrees into radians is:", ""] return result; }; templateString = printOfResultOnly`Conversion: ${degrees} degrees into radians is: ${(degrees * Math.PI) / 180}`;
  • 17. Classes are a better syntax over the prototype object. What we will get in the bundle? ⚬ Creation of instances via ‘new’ keyword. ⚬ Encapsulating fields and functions that relevant the class. ⚬ Intuitive constructor is exist. ⚬ Even extend and override a methods! ⚬ Defining of static members. ⚬ Note that we cannot define private members. Classes class Animal { constructor(age = 0) { this.age = age; } eat() {} }
  • 18. Example of inheritance: Classes class Cat extends Animal { constructor(age, name) { super(age); this.name = name; } eat() { return `I am ${this.name}, and i love milk!`; } } let kitty = new Cat(5, 'Kitty');
  • 19. Until now, were two main approaches for modules: ⚬ CommonJS - Compact API that designed for synchronized loading. It focuses in the server side. Motivation: Simple and clear syntax. Main Implementations: Node.js, RingoJS. ⚬ Asynchronous Module Definition - More complex API that designed for asynchronous loading. It focuses in the client side. Motivation: Dependency management. Main Implementation: RequireJS. Modules
  • 20. Modules are even more simple than CommonJS together with the supporting in asynchronous loading of AMD! There are two new keywords: export and import. Example of using: Modules // math.js export const PI = Math.PI; export function square(x) { return x*x; } // app.js import {PI, square} from 'math'; // Alternatively, could be: import * as math from ‘math’ console.log(square(PI)); // Will be PI^2
  • 21. Rest parameters is a better alternative to arguments. The rest parameter is an array that marked by ‘...’ (three points). All parameters that will be delivered from this location, will be in this array. Example of using: Rest Parameters let myFunction = function(x, ...parametersThatIDontCare) { // parametersThatIDontCare = [true, 'Cool String'] return x * parametersThatIDontCare.length; }; myFunction(10, true, 'Cool String'); // Will be 20
  • 22. Spread operator allows to deliver an array, and separate it to multiple parameters in the declaration of function. It should be inverse of rest parameters. Example of using: Spread Operator let myFunction = function(str, x, y, z) { return str + (x+y+z); }; myFunction('The sum is:', ...[1, 10, 100]);
  • 23. Destructuring is way to select a specific arguments from array or object into variables. Actually, destructuring is matching between two collections by different patterns. Example of using: Destructuring let [a, , , b] = [1, 3, 5, 9]; console.log('a + b is: ' + (a + b)); // Will be 10 let { one, two, three: [, threeValue] } = { one: 1, two: 2, three: [4, 3] }; console.log('one + two + three is: ' + (one + two + threeValue)); // Will be 6 let [d, c] = [c, d]; // Swap the values without temp!
  • 24. Symbol is new primitive type that used as private reference to property. Symbols are unique! The file must hold this symbol to access the property of object. Example of using: Symbols var privateProperty = Symbol('Description: Private property'); var object = {}; object[privateProperty] = 'My Private'; console.log(privateProperty); // Is a symbol console.log(object[privateProperty]); // Will print 'My Private'
  • 25. Map is dictionary data structure that stores pairs of key and value. Difference from object, now the key can be an object! Map provides an API with: set, get, clear, forEach, size, and more! Example of using: Maps let objectKey = {value: 100}; let map = new Map(); map.set('stringKey', 'The value is '); map.set(objectKey, objectKey.value); console.log(map.get('stringKey') + map.get(objectKey)); // Will be 'The value is 100' console.log('Map size: ' + map.size); // Will be 2
  • 26. Set is data structure of collection of values. It wraps the old object with better API. It provides an API with: add, has, clear, forEach, size, and more! Example of using: Sets let mySetList = new Set(); mySetList.add('First').add('Second'); mySetList.add(true); console.log(mySetList); // Will be {"First", "Second", true} console.log(mySetList.has('Second')); // Will be true
  • 27. Along all main features, little changes in numbers were made. Until now, the methods isFinite and isNaN could get numbers as string: Now, we have those methods in part of Number, which will accept only numbers values: Little changes of Numbers console.log(isFinite("1")); // Will be true console.log(isNaN("NaN")); // Will be true console.log(Number.isFinite("1")); // Will be false console.log(Number.isNaN("NaN")); // Will be false
  • 28. Added function to identify if it is an integer! Added a lot of new Math methods! For example: ⚬ Math.acosh(x), Math.asinh(x), Math.atanh(x) ⚬ Math.log1p(x), Math.log10(x), Math.log2(x) ⚬ Math.trunc(x) Little changes of Numbers console.log(Number.isInteger(25.5)); // Will be false
  • 29. ⚬ Object.observe - Allows to register to changes of data model by callback (Feature of ES7). ⚬ Promises - Asynchronous operations. ⚬ Generators - Special functions that creates a type of iterators. ⚬ Proxies - Creating a proxy on a particular object allows a predefined handler to get notified when something happens. ⚬ Array comprehensions - Syntax that allows you to quickly assemble a new array based on an existing one (Feature of ES7). ⚬ Tail call optimization - Instead of create new stack frames, It reuses old stack frames. Unspoken features
  • 30. ⚬ ECMAScript 6 standard of scripting languages. ⚬ ECMAScript 6 will be published on June 2015. ⚬ ECMAScript 6 will bring a lot of changes: ○ Arrows ○ let & const ○ Default parameters, Rest Parameters ○ Spread Operator ○ Template Strings ○ Classes & Modules ○ Destructuring ○ Symbols ○ Maps & Sets ○ Minor changes of Numbers Conclusions