SlideShare a Scribd company logo
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
d = 'ev';
var d;
console.log(d);
var d;
d = 'ev';
console.log(d);
Only the declarations themselves are hoisted, while any assignments or
other executable logic are left in place.
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
test(); // 1
var test;
function test() {
console.log(1);
}
test = function () {
console.log(2);
};
function test() {
console.log(1);
}
test(); // 1
test = function () {
console.log(2);
};
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
function add(num1, num2) {
var sum = num1 + num2;
return sum;
}
Add
[[Scope]]
Scope Chain
0
Global Object
this Windows
windows (object)
document (object)
add (function)
… …
add.length === 2;
Object.getPrototypeOf(add) === Function.prototype;
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Activation object
this Windows
arguments [ 5 , 10 ]
num1 5
num2 10
sum undefined
var Total = add( 5 , 10 );
add(5,10)
Execution
context
Scope
chain
Scope Chain
0
1
Global Object
this Windows
windows (object)
document (object)
add (function)
… …
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var color = "blue";
function changeColor() {
var anotherColor = "red";
function swapColors(){
var tempColor = anotherColor;
anotherColor = color;
color = tempColor;
// color, anotherColor, and tempColor
// are all accessible here.
}
// color and anotherColor are accessible here,
// but not tempColor.
swapColors();
}
//only color is accessible here
changeColor();
Windows
color
changeColor()
anotherColor
swapColos() tempColor()
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
function addEvent() {
var id = "xdi9592";
document.getElementById("save-btn").onclick =
function (event) {
saveDocument( id );
};
}
From parent
scope
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Scope Chain
0
1
Activation object
this Windows
arguments []
id “xdi9592”
addEvent()
Execution context
Scope chain
Scope Chain
0
1
Global Object
this Windows
windows (object)
document (object)
addEvent (function)
saveDoc (function)
Closure
[[Scope]]
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Scope Chain
0
1
2
Activation object
this Windows
arguments []
id “xdi9592”
Global Object
this Windows
windows (object)
document (object)
addEvent (function)
saveDoc (function)
Closure
execution context
[[Scope]]
Activation object
(closure)
this Windows
arguments []
event (object)
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var funcs = [];
for ( var i = 0; i < 10; i ++) {
funcs.push( function() { console.log(i); });
}
funcs.forEach( function(func) {
func(); // outputs the number "10" ten times
});
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var funcs = [];
for ( var i = 0; i < 10; i ++) {
funcs.push(( function(value) {
return function() {
console.log(value);
}
}(i)));
}
funcs.forEach( function(func) {
func(); // outputs 0, 1, 2, 3, up to 9
});
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var funcs = [];
for ( let i = 0; i < 10; i ++) {
funcs.push( function() { console.log(i); });
}
funcs.forEach( function(func) {
func(); // outputs 0, 1, 2, 3, up to 9
});
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
const PI = 3.14159;
// Can't re-assign
PI = 3;
console.log(PI); // 3.14159
// Can't re-initialize
const PI = 4;
console.log(PI); // 3.14159
// Can't re-declare
var PI = 4;
console.log(PI); // 3.14159
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
 Undefined
 Null
function history( lang = "C", year = 1971 ) {
// lang = lang || "C";
// year = year || 1971;
return lang + " was created around the year " + year;
}
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
// defining rest parameters with 3 dot syntax
function push(array, ...items) {
items.forEach(function(item) {
array.push(item);
console.log( item );
});
}
// 1 fixed + 3 variable parameters
var planets = [];
push(planets, "Mercury", "Venus", "Earth");
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Spread
operator
let values = [25, 50, 75, 100];
Math.max.apply( Math , values );
Math.max(...values);
Math.max(...values , 200 , 300 );
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var f= x => x;
var f= (n1,n2) => n1+n2;
var f= id => ({id:id,name:"T"});
var f = function(x) {
return x;
}
var f = function(n1,n2) {
return n1 + n2;
}
var f = function(id) {
return {
id: id,
name: "T"
};
}
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var PageHandler = {
id: "123456",
init: function() {
document.addEventListener("click", function(event) {
this.doSomething(event.type); // error
}, false);
},
doSomething: function(type) {
console.log("Handling " + type + " for " + this.id);
}
};
Global
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var PageHandler = {
id: "123456",
init: function() {
document.addEventListener("click", (function(event) {
this.doSomething(event.type);
}).bind(this), false);
},
doSomething: function(type) {
console.log("Handling " + type + " for " + this.id);
}
}
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var PageHandler = {
id: "123456",
init: function() {
document.addEventListener("click",
event => this.doSomething(event.type), false);
},
doSomething: function(type) {
console.log("Handling "+type+" for " + this.id);
}
};
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
let v = ( function(name) {
return {
getName() {
return name;
}
};
}( "Eyal" ) );
let v = ( (name) => {
return {
getName() {
return name;
}
};
})( "Eyal" );
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
http://www.2ality.com/
Understanding ECMAScript 6
http://ecmascript6.org/
A Few New Things Coming To JavaScript
HARMONY OF DREAMS COME TRUE
Harmony specification_drafts
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
eyalvardi.wordpress.com

More Related Content

What's hot

GlueCon 2016 - Threading in JavaScript
GlueCon 2016 - Threading in JavaScriptGlueCon 2016 - Threading in JavaScript
GlueCon 2016 - Threading in JavaScript
Jonathan Baker
 
Creating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with googleCreating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with google
Roel Hartman
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2sajidpk92
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
Bootiful Development with Spring Boot and React
Bootiful Development with Spring Boot and ReactBootiful Development with Spring Boot and React
Bootiful Development with Spring Boot and React
VMware Tanzu
 
Angular animate
Angular animateAngular animate
Angular animate
Yating Chatiron
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API's
Roel Hartman
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
Ignacio Martín
 
Introduction to Angular js
Introduction to Angular jsIntroduction to Angular js
Introduction to Angular jsMustafa Gamal
 
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Damien Carbery
 
[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes
Globant
 
A (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesA (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project Files
David Wengier
 
누구나 할 수 있다 Networking
누구나 할 수 있다 Networking누구나 할 수 있다 Networking
누구나 할 수 있다 Networking
Jungwon An
 
A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014
Damien Seguy
 
Programação reativa e o actor model
Programação reativa e o actor modelProgramação reativa e o actor model
Programação reativa e o actor model
Fabrício Rissetto
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?
Anna Su
 
Testing Services Effectively
Testing Services Effectively Testing Services Effectively
Testing Services Effectively
Alberto Leal
 
Programs
ProgramsPrograms
Practical Google App Engine Applications In Py
Practical Google App Engine Applications In PyPractical Google App Engine Applications In Py
Practical Google App Engine Applications In Py
Eric ShangKuan
 
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
Of Harmony and Stinginess: Applicative, Monad, and iterative library designOf Harmony and Stinginess: Applicative, Monad, and iterative library design
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
jspha
 

What's hot (20)

GlueCon 2016 - Threading in JavaScript
GlueCon 2016 - Threading in JavaScriptGlueCon 2016 - Threading in JavaScript
GlueCon 2016 - Threading in JavaScript
 
Creating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with googleCreating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with google
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
 
Bootiful Development with Spring Boot and React
Bootiful Development with Spring Boot and ReactBootiful Development with Spring Boot and React
Bootiful Development with Spring Boot and React
 
Angular animate
Angular animateAngular animate
Angular animate
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API's
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
Introduction to Angular js
Introduction to Angular jsIntroduction to Angular js
Introduction to Angular js
 
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
 
[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes
 
A (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesA (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project Files
 
누구나 할 수 있다 Networking
누구나 할 수 있다 Networking누구나 할 수 있다 Networking
누구나 할 수 있다 Networking
 
A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014
 
Programação reativa e o actor model
Programação reativa e o actor modelProgramação reativa e o actor model
Programação reativa e o actor model
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?
 
Testing Services Effectively
Testing Services Effectively Testing Services Effectively
Testing Services Effectively
 
Programs
ProgramsPrograms
Programs
 
Practical Google App Engine Applications In Py
Practical Google App Engine Applications In PyPractical Google App Engine Applications In Py
Practical Google App Engine Applications In Py
 
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
Of Harmony and Stinginess: Applicative, Monad, and iterative library designOf Harmony and Stinginess: Applicative, Monad, and iterative library design
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
 

Viewers also liked

My Portfolio
My PortfolioMy Portfolio
My Portfolio
kaufmanndesigns
 
Mb880 CAN BUS manual-How to Use MB880 CAN BUS Auto Scanner
Mb880 CAN BUS manual-How to Use MB880 CAN BUS Auto ScannerMb880 CAN BUS manual-How to Use MB880 CAN BUS Auto Scanner
Mb880 CAN BUS manual-How to Use MB880 CAN BUS Auto Scanner
Bill Zhao
 
Muebles de jardín colección 2013 de Greendesign by fast 2013
Muebles de jardín colección 2013 de Greendesign by fast 2013Muebles de jardín colección 2013 de Greendesign by fast 2013
Muebles de jardín colección 2013 de Greendesign by fast 2013
Greendesign
 
Wifiway exposición - Jorlyn Vilchez Tixe
Wifiway exposición - Jorlyn Vilchez TixeWifiway exposición - Jorlyn Vilchez Tixe
Wifiway exposición - Jorlyn Vilchez TixeJordyArce Vilchez T
 
Improving Speed to Market in E-commerce
Improving Speed to Market in E-commerceImproving Speed to Market in E-commerce
Improving Speed to Market in E-commerce
Cognizant
 
CV 2.0 Mauricio Sebastián Melillo
CV 2.0 Mauricio Sebastián MelilloCV 2.0 Mauricio Sebastián Melillo
CV 2.0 Mauricio Sebastián Melillo
mmelillo
 
Raritan Dominion KX101 User Guide
Raritan Dominion KX101 User GuideRaritan Dominion KX101 User Guide
Raritan Dominion KX101 User Guide
kvz
 
Homenaje A Lino Palacios
Homenaje A Lino PalaciosHomenaje A Lino Palacios
Homenaje A Lino Palacioscuartogradoiji
 
Camfil Truly Green Air Filters Brochure
Camfil Truly Green Air Filters BrochureCamfil Truly Green Air Filters Brochure
Camfil Truly Green Air Filters BrochureAdam Wiggins
 
Comunicado conjunto osos bd cam
Comunicado conjunto osos bd camComunicado conjunto osos bd cam
Comunicado conjunto osos bd cam
Miguel Bayod
 
Kreative Kampagnen im Social Web. Erfolgsgarant oder Rohrkrepierer?
Kreative Kampagnen im Social Web. Erfolgsgarant oder Rohrkrepierer?Kreative Kampagnen im Social Web. Erfolgsgarant oder Rohrkrepierer?
Kreative Kampagnen im Social Web. Erfolgsgarant oder Rohrkrepierer?
ScribbleLive
 
Infonet Economy - Das Wirtschaftsinformationsportal
Infonet Economy - Das WirtschaftsinformationsportalInfonet Economy - Das Wirtschaftsinformationsportal
Infonet Economy - Das Wirtschaftsinformationsportal
Eliane Blumer
 
Revitalizacao paraiba maio.14
Revitalizacao paraiba maio.14Revitalizacao paraiba maio.14
Revitalizacao paraiba maio.14Luciana Falk
 
Razones financieras expendio corona
Razones financieras expendio coronaRazones financieras expendio corona
Razones financieras expendio corona
Gabriela Mathers Lara
 
Diseño y Usabilidad
Diseño y UsabilidadDiseño y Usabilidad
Diseño y UsabilidadDomestika
 
Ian Franklyn Digital Specialist
Ian Franklyn Digital SpecialistIan Franklyn Digital Specialist
Ian Franklyn Digital Specialist
Ian Franklyn
 
PrintersPlus GTEC 2013 Brochure - Managed Print Services
PrintersPlus GTEC 2013 Brochure - Managed Print ServicesPrintersPlus GTEC 2013 Brochure - Managed Print Services
PrintersPlus GTEC 2013 Brochure - Managed Print Services
PrintersPlus_Ottawa
 
¿Que es AMPI?
¿Que es AMPI?¿Que es AMPI?
¿Que es AMPI?
Expansión Ampi
 
In a fictional world,will Product Manager define also Services?
In a fictional world,will Product Manager define also Services?In a fictional world,will Product Manager define also Services?
In a fictional world,will Product Manager define also Services?
C-urVision Ltd. Making Innovation Work
 

Viewers also liked (20)

My Portfolio
My PortfolioMy Portfolio
My Portfolio
 
Mb880 CAN BUS manual-How to Use MB880 CAN BUS Auto Scanner
Mb880 CAN BUS manual-How to Use MB880 CAN BUS Auto ScannerMb880 CAN BUS manual-How to Use MB880 CAN BUS Auto Scanner
Mb880 CAN BUS manual-How to Use MB880 CAN BUS Auto Scanner
 
Muebles de jardín colección 2013 de Greendesign by fast 2013
Muebles de jardín colección 2013 de Greendesign by fast 2013Muebles de jardín colección 2013 de Greendesign by fast 2013
Muebles de jardín colección 2013 de Greendesign by fast 2013
 
Wifiway exposición - Jorlyn Vilchez Tixe
Wifiway exposición - Jorlyn Vilchez TixeWifiway exposición - Jorlyn Vilchez Tixe
Wifiway exposición - Jorlyn Vilchez Tixe
 
Sicología..
Sicología..Sicología..
Sicología..
 
Improving Speed to Market in E-commerce
Improving Speed to Market in E-commerceImproving Speed to Market in E-commerce
Improving Speed to Market in E-commerce
 
CV 2.0 Mauricio Sebastián Melillo
CV 2.0 Mauricio Sebastián MelilloCV 2.0 Mauricio Sebastián Melillo
CV 2.0 Mauricio Sebastián Melillo
 
Raritan Dominion KX101 User Guide
Raritan Dominion KX101 User GuideRaritan Dominion KX101 User Guide
Raritan Dominion KX101 User Guide
 
Homenaje A Lino Palacios
Homenaje A Lino PalaciosHomenaje A Lino Palacios
Homenaje A Lino Palacios
 
Camfil Truly Green Air Filters Brochure
Camfil Truly Green Air Filters BrochureCamfil Truly Green Air Filters Brochure
Camfil Truly Green Air Filters Brochure
 
Comunicado conjunto osos bd cam
Comunicado conjunto osos bd camComunicado conjunto osos bd cam
Comunicado conjunto osos bd cam
 
Kreative Kampagnen im Social Web. Erfolgsgarant oder Rohrkrepierer?
Kreative Kampagnen im Social Web. Erfolgsgarant oder Rohrkrepierer?Kreative Kampagnen im Social Web. Erfolgsgarant oder Rohrkrepierer?
Kreative Kampagnen im Social Web. Erfolgsgarant oder Rohrkrepierer?
 
Infonet Economy - Das Wirtschaftsinformationsportal
Infonet Economy - Das WirtschaftsinformationsportalInfonet Economy - Das Wirtschaftsinformationsportal
Infonet Economy - Das Wirtschaftsinformationsportal
 
Revitalizacao paraiba maio.14
Revitalizacao paraiba maio.14Revitalizacao paraiba maio.14
Revitalizacao paraiba maio.14
 
Razones financieras expendio corona
Razones financieras expendio coronaRazones financieras expendio corona
Razones financieras expendio corona
 
Diseño y Usabilidad
Diseño y UsabilidadDiseño y Usabilidad
Diseño y Usabilidad
 
Ian Franklyn Digital Specialist
Ian Franklyn Digital SpecialistIan Franklyn Digital Specialist
Ian Franklyn Digital Specialist
 
PrintersPlus GTEC 2013 Brochure - Managed Print Services
PrintersPlus GTEC 2013 Brochure - Managed Print ServicesPrintersPlus GTEC 2013 Brochure - Managed Print Services
PrintersPlus GTEC 2013 Brochure - Managed Print Services
 
¿Que es AMPI?
¿Que es AMPI?¿Que es AMPI?
¿Que es AMPI?
 
In a fictional world,will Product Manager define also Services?
In a fictional world,will Product Manager define also Services?In a fictional world,will Product Manager define also Services?
In a fictional world,will Product Manager define also Services?
 

Similar to Scope & Functions in ECMAScript 6.0

What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0
Eyal Vardi
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
Eyal Vardi
 
ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
Giacomo Zinetti
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 Simplified
Carlos Ble
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
Sri Harsha Pamu
 
The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)
Aaron Gustafson
 
TDD Boot Camp 東京 for C++ 進行
TDD Boot Camp 東京 for C++ 進行TDD Boot Camp 東京 for C++ 進行
TDD Boot Camp 東京 for C++ 進行Takashi Imagire
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
monikagupta18jan
 
C++ Generators and Property-based Testing
C++ Generators and Property-based TestingC++ Generators and Property-based Testing
C++ Generators and Property-based Testing
Sumant Tambe
 
GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
GDSCVJTI
 
Node.js Event Emitter
Node.js Event EmitterNode.js Event Emitter
Node.js Event Emitter
Eyal Vardi
 
Swift - Krzysztof Skarupa
Swift -  Krzysztof SkarupaSwift -  Krzysztof Skarupa
Swift - Krzysztof Skarupa
Sunscrapers
 
Introduction to ES2015
Introduction to ES2015Introduction to ES2015
Introduction to ES2015
kiranabburi
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
Mark
 
Rust
RustRust
R57shell
R57shellR57shell
R57shell
ady36
 
Rust Intro
Rust IntroRust Intro
Rust Intro
Arthur Gavkaluk
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
Demian Holderegger
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better code
Dror Helper
 

Similar to Scope & Functions in ECMAScript 6.0 (20)

What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
 
ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 Simplified
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)
 
TDD Boot Camp 東京 for C++ 進行
TDD Boot Camp 東京 for C++ 進行TDD Boot Camp 東京 for C++ 進行
TDD Boot Camp 東京 for C++ 進行
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
C++ Generators and Property-based Testing
C++ Generators and Property-based TestingC++ Generators and Property-based Testing
C++ Generators and Property-based Testing
 
GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
 
Node.js Event Emitter
Node.js Event EmitterNode.js Event Emitter
Node.js Event Emitter
 
Swift - Krzysztof Skarupa
Swift -  Krzysztof SkarupaSwift -  Krzysztof Skarupa
Swift - Krzysztof Skarupa
 
Introduction to ES2015
Introduction to ES2015Introduction to ES2015
Introduction to ES2015
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Rust
RustRust
Rust
 
R57shell
R57shellR57shell
R57shell
 
Rust Intro
Rust IntroRust Intro
Rust Intro
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better code
 

More from Eyal Vardi

Why magic
Why magicWhy magic
Why magic
Eyal Vardi
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
Eyal Vardi
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
Eyal Vardi
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
Eyal Vardi
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time CompilationAngular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
Eyal Vardi
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
Eyal Vardi
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
Eyal Vardi
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
Eyal Vardi
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
Eyal Vardi
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
Eyal Vardi
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
Eyal Vardi
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
Eyal Vardi
 

More from Eyal Vardi (20)

Why magic
Why magicWhy magic
Why magic
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time CompilationAngular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 

Recently uploaded

How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 

Recently uploaded (20)

How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 

Scope & Functions in ECMAScript 6.0

  • 1. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 2. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com d = 'ev'; var d; console.log(d); var d; d = 'ev'; console.log(d); Only the declarations themselves are hoisted, while any assignments or other executable logic are left in place.
  • 3. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com test(); // 1 var test; function test() { console.log(1); } test = function () { console.log(2); }; function test() { console.log(1); } test(); // 1 test = function () { console.log(2); };
  • 4. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com function add(num1, num2) { var sum = num1 + num2; return sum; } Add [[Scope]] Scope Chain 0 Global Object this Windows windows (object) document (object) add (function) … … add.length === 2; Object.getPrototypeOf(add) === Function.prototype;
  • 5. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com Activation object this Windows arguments [ 5 , 10 ] num1 5 num2 10 sum undefined var Total = add( 5 , 10 ); add(5,10) Execution context Scope chain Scope Chain 0 1 Global Object this Windows windows (object) document (object) add (function) … …
  • 6. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var color = "blue"; function changeColor() { var anotherColor = "red"; function swapColors(){ var tempColor = anotherColor; anotherColor = color; color = tempColor; // color, anotherColor, and tempColor // are all accessible here. } // color and anotherColor are accessible here, // but not tempColor. swapColors(); } //only color is accessible here changeColor(); Windows color changeColor() anotherColor swapColos() tempColor()
  • 7. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com function addEvent() { var id = "xdi9592"; document.getElementById("save-btn").onclick = function (event) { saveDocument( id ); }; } From parent scope
  • 8. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com Scope Chain 0 1 Activation object this Windows arguments [] id “xdi9592” addEvent() Execution context Scope chain Scope Chain 0 1 Global Object this Windows windows (object) document (object) addEvent (function) saveDoc (function) Closure [[Scope]]
  • 9. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com Scope Chain 0 1 2 Activation object this Windows arguments [] id “xdi9592” Global Object this Windows windows (object) document (object) addEvent (function) saveDoc (function) Closure execution context [[Scope]] Activation object (closure) this Windows arguments [] event (object)
  • 10. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var funcs = []; for ( var i = 0; i < 10; i ++) { funcs.push( function() { console.log(i); }); } funcs.forEach( function(func) { func(); // outputs the number "10" ten times });
  • 11. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var funcs = []; for ( var i = 0; i < 10; i ++) { funcs.push(( function(value) { return function() { console.log(value); } }(i))); } funcs.forEach( function(func) { func(); // outputs 0, 1, 2, 3, up to 9 });
  • 12. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var funcs = []; for ( let i = 0; i < 10; i ++) { funcs.push( function() { console.log(i); }); } funcs.forEach( function(func) { func(); // outputs 0, 1, 2, 3, up to 9 });
  • 13. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com const PI = 3.14159; // Can't re-assign PI = 3; console.log(PI); // 3.14159 // Can't re-initialize const PI = 4; console.log(PI); // 3.14159 // Can't re-declare var PI = 4; console.log(PI); // 3.14159
  • 14. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 15. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 16. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com  Undefined  Null function history( lang = "C", year = 1971 ) { // lang = lang || "C"; // year = year || 1971; return lang + " was created around the year " + year; }
  • 17. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com // defining rest parameters with 3 dot syntax function push(array, ...items) { items.forEach(function(item) { array.push(item); console.log( item ); }); } // 1 fixed + 3 variable parameters var planets = []; push(planets, "Mercury", "Venus", "Earth");
  • 18. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com Spread operator let values = [25, 50, 75, 100]; Math.max.apply( Math , values ); Math.max(...values); Math.max(...values , 200 , 300 );
  • 19. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 20. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var f= x => x; var f= (n1,n2) => n1+n2; var f= id => ({id:id,name:"T"}); var f = function(x) { return x; } var f = function(n1,n2) { return n1 + n2; } var f = function(id) { return { id: id, name: "T" }; }
  • 21. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var PageHandler = { id: "123456", init: function() { document.addEventListener("click", function(event) { this.doSomething(event.type); // error }, false); }, doSomething: function(type) { console.log("Handling " + type + " for " + this.id); } }; Global
  • 22. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var PageHandler = { id: "123456", init: function() { document.addEventListener("click", (function(event) { this.doSomething(event.type); }).bind(this), false); }, doSomething: function(type) { console.log("Handling " + type + " for " + this.id); } }
  • 23. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var PageHandler = { id: "123456", init: function() { document.addEventListener("click", event => this.doSomething(event.type), false); }, doSomething: function(type) { console.log("Handling "+type+" for " + this.id); } };
  • 24. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com let v = ( function(name) { return { getName() { return name; } }; }( "Eyal" ) ); let v = ( (name) => { return { getName() { return name; } }; })( "Eyal" );
  • 25. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com http://www.2ality.com/ Understanding ECMAScript 6 http://ecmascript6.org/ A Few New Things Coming To JavaScript HARMONY OF DREAMS COME TRUE Harmony specification_drafts
  • 26. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com eyalvardi.wordpress.com