SlideShare ist ein Scribd-Unternehmen logo
1 von 32
ES6 ES2015 is Beautiful
Agenda
Go through ES6 features
Look at random cute animal pics
Let(me be!)
var x = 5; let x = 5;
if (1) {
let x = 20;
}
console.log(x);
if (1) {
var x = 20;
}
console.log(x);
Block Scope
Usage
Let
for (var i=0; i<5; i++) {
setTimeout( function() {
console.log(i);
}, 100);
}
for (var i=0; i<5; i++) {
(function (scopedI){
setTimeout( function() {
console.log(scopedI);
}, 100);
})(i);
}
for (let i=0; i<5; i++) {
setTimeout( function() {
console.log(i);
}, 100);
}
Avoid Crazy bugs
(no) Strings (attached)
var name = 'Monika';
console.log('My name is ' + name);
let name2 = 'Monika';
console.log(`My name is ${name2}`);
var str = 'Template strings providen' +
'syntactic sugar forn' +
'constructing strings.';
let str2 = `Template strings provide
syntactic sugar for
constructing strings.`
Variable Bindings
Multiline Strings
Strings
const headline = 'Yahoo products are beautiful.'
headline.startsWith('Yahoo')
// true
headline.endsWith('beautiful')
// true
headline.includes('products')
// true
headline.includes('.')
// false
headline.repeat(2);
//Yahoo products are beautiful.Yahoo products are beautiful.
More
awesomeness!
Arrays
var divsArray = [].slice.call(document.querySelectorAll('div'));
divsArray.forEach(function(node) {
console.log(node);
});
let divs = document.querySelectorAll('div');
Array.from(divs).forEach(node => {
console.log(node);
});
var names = ["Monika", "Seth", "Nikhil", "Mallika"];
var res = names.filter(function (name) {
return name === "Monika"; }
)[0];
let names2 = ["Monika", "Seth", "Nikhil", "Mallika"];
let res2 = names.find(function (name) {
return name === "Monika"; }
);
Array like
Find one element
Function Shorthand
var fun = function() {
console.log('Yay!')
};
let fun2 = () => console.log('Yay!');
var nums = [1,2,3,4,5];
var numsPlus2 =
nums.map(function(num) {
return num + 2;
});
var nums2 = [1,2,3,4,5];
var nums2Plus2 = nums.map(num => num + 2);
Usage
Awesomeness
Function Shorthand
this.x = 42;
setTimeout( function(){
console.log(this.x);
}, 100);
this.x = 42;
var self = this;
setTimeout( function(){
console.log(self.x);
}, 100);
this.x = 42;
setTimeout(() => console.log(this.x), 100);
More Awesomeness
Function Parameters - default
function f(x, y) {
if (!y) {
y = 1;
}
return x * y;
}
function f(x, y) {
// y is 12 if not passed (or passed as undefined)
if (typeof y === 'undefined') {
y = 1;
}
return x * y;
}
function f(x, y=1) {
return x * y;
}
Function Parameters - Spread...
var nums = [9,10,2];
Math.max(...nums);
var nums = [9,10,2];
Math.max(nums);
var nums = [9,10,2];
Math.max.apply(null, nums);
Function Parameters - Rest...
function join(sep, ...nums) {
return nums.join(sep);
}
function join(sep) {
var args = [].slice.call(arguments, 1);
return args.join(sep);
}
join(':', 1, 2, 3);
join(':', 1, 2);
Object (of my affection) - Destructuring
const { user, post } = this.props;var user = this.props.user,
post = this.props.post;
function fun({x, y, z=100}) {
return x + y + z;
}
fun({x:3, y:2}); // 105
function fun(data) {
return data.x + data.y;
}
fun({x:3, y:2});
function fun({x,y}) {
return x + y;
}
fun({x:3, y:2});
Destructuring with
default params
Objects Literals Extension
var obj = {
// defining prototype on object creation
__proto__: theProtoObj,
// shortcut for ‘handler: handler’
handler,
// shortcut for methods - 'toString: function() {}'
toString() {
// base class method call with 'super'
return 'd ' + super.toString();
},
// dynamic property names
[ 'prop_' + (() => 42)() ]: 42
};
(Very) Class(ey)
var Shape = function (id, x, y) {
this.id = id;
this.move(x, y);
};
Shape.prototype.move = function (x, y) {
this.x = x;
this.y = y;
};
class Shape {
constructor (id, x, y) {
this.id = id
this.move(x, y)
}
move (x, y) {
this.x = x
this.y = y
}
}
Class Inheritance
var Rectangle = function (id, x, y, width, height) {
Shape.call(this, id, x, y);
this.width = width;
this.height = height;
};
Rectangle.prototype = Object.create(Shape.prototype);
Rectangle.prototype.constructor = Rectangle;
class Rectangle extends Shape {
constructor (id, x, y, width, height) {
super(id, x, y)
this.width = width
this.height = height
}
}
Promise (me, you will come back..)
function timeout(duration = 0) {
return new Promise((resolve, reject) => {
setTimeout(resolve, duration);
})
}
var p = timeout(1000).then(() => {
console.log('Done after 1000 sec');
});
var request = require('request');
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1;
function foo(finalCallback) {
request.get(url1, function(err1, res1) {
if (err1) { return finalCallback(err1); }
request.post(url2, function(err2, res2) {
if (err2) { return finalCallback(err2); }
request.put(url3, function(err3, res3) {
if (err3) { return finalCallback(err3); }
request.del(url4, function(err4, res4) {
// let's stop here
if (err4) { return finalCallback(err4); }
finalCallback(null, "whew all done");
})
})
})
})
}
// use that function somewhere
foo(function(err, message) {
if (err) {
return console.log("error!", err);
}
console.log("success!", message);
});
var Promise = require('bluebird');
var request = Promise.promisifyAll(require('request'));
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1;
function foo() {
return request.getAsync(url1)
.then(function(res1) {
return request.postAsync(url2);
}).then(function(res2) {
return request.putAsync(url3);
}).then(function(res3) {
return request.delAsync(url4);
}).then(function(res4) {
return "whew all done";
});
}
// use that function somewhere
foo().then(function(message) {
console.log("success!", message);
}).catch(function(err) {
console.log("error!", err);
});
Promise
var Promise = require('bluebird');
var request = Promise.promisifyAll(require('request'));
var url1='http://httpbin.org/', url2=url1, url3=url1,
url4=url1;
async function foo() {
var res1 = await request.getAsync(url1);
var res2 = await request.getAsync(url2);
var res3 = await request.getAsync(url3);
var res4 = await request.getAsync(url4);
return "whew all done";
}
// use that function somewhere
foo().then(function(message) {
console.log("success!", message);
}).catch(function(err) {
console.log("error!", err);
});
Async/ Await - Glimpse
So much more..
Modules
Proxy
Generator, Iterator
Maps, Sets
Proxy
Symbols
More...
Browser compatible?
Javascript compiler
Use Next Generation Javascript Today!
http://babeljs.io/
Babel
Quick Demo
Using babel-cli
Presets
Pubs presets
npm install --save-dev babel-cli
babel test.js
ynpm install --save-dev babel-preset-pubs
babel test.js --presets=pubs
// Use .babelrc
Links
https://yo/es6beauty
http://www.ecma-international.org/ecma-262/6.0/
http://es6-features.org
https://babeljs.io/
QnA

Weitere ähnliche Inhalte

Was ist angesagt?

The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 40 of 84
The Ring programming language version 1.2 book - Part 40 of 84The Ring programming language version 1.2 book - Part 40 of 84
The Ring programming language version 1.2 book - Part 40 of 84Mahmoud Samir Fayed
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84Mahmoud Samir Fayed
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignmentashikul akash
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonChristoph Matthies
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
The Ring programming language version 1.3 book - Part 46 of 88
The Ring programming language version 1.3 book - Part 46 of 88The Ring programming language version 1.3 book - Part 46 of 88
The Ring programming language version 1.3 book - Part 46 of 88Mahmoud Samir Fayed
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsBaruch Sadogursky
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utilsroxlu
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184Mahmoud Samir Fayed
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory archana singh
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2MEJenchoke Tachagomain
 

Was ist angesagt? (20)

Csharp_Chap13
Csharp_Chap13Csharp_Chap13
Csharp_Chap13
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212
 
The Ring programming language version 1.2 book - Part 40 of 84
The Ring programming language version 1.2 book - Part 40 of 84The Ring programming language version 1.2 book - Part 40 of 84
The Ring programming language version 1.2 book - Part 40 of 84
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84
 
Promise is a Promise
Promise is a PromisePromise is a Promise
Promise is a Promise
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
BingoConsoleApp
BingoConsoleAppBingoConsoleApp
BingoConsoleApp
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in Python
 
Acm
AcmAcm
Acm
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
The Ring programming language version 1.3 book - Part 46 of 88
The Ring programming language version 1.3 book - Part 46 of 88The Ring programming language version 1.3 book - Part 46 of 88
The Ring programming language version 1.3 book - Part 46 of 88
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
 
Property-based testing
Property-based testingProperty-based testing
Property-based testing
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 

Ähnlich wie ES6(ES2015) is beautiful

Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming heroThe Software House
 
深入浅出Jscex
深入浅出Jscex深入浅出Jscex
深入浅出Jscexjeffz
 
Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)jeffz
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new featuresGephenSG
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Will Kurt
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)hhliu
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMDdhaval10690
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Javascript Uncommon Programming
Javascript Uncommon ProgrammingJavascript Uncommon Programming
Javascript Uncommon Programmingjeffz
 
Call stack, event loop and async programming
Call stack, event loop and async programmingCall stack, event loop and async programming
Call stack, event loop and async programmingMasters Academy
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React AlicanteIgnacio Martín
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency명신 김
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingSergey Shishkin
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017名辰 洪
 

Ähnlich wie ES6(ES2015) is beautiful (20)

Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming hero
 
深入浅出Jscex
深入浅出Jscex深入浅出Jscex
深入浅出Jscex
 
Javascript
JavascriptJavascript
Javascript
 
Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Monadologie
MonadologieMonadologie
Monadologie
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMD
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Javascript Uncommon Programming
Javascript Uncommon ProgrammingJavascript Uncommon Programming
Javascript Uncommon Programming
 
Call stack, event loop and async programming
Call stack, event loop and async programmingCall stack, event loop and async programming
Call stack, event loop and async programming
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional Programming
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 

Kürzlich hochgeladen

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Kürzlich hochgeladen (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

ES6(ES2015) is beautiful

  • 1. ES6 ES2015 is Beautiful
  • 2. Agenda Go through ES6 features Look at random cute animal pics
  • 3.
  • 4. Let(me be!) var x = 5; let x = 5; if (1) { let x = 20; } console.log(x); if (1) { var x = 20; } console.log(x); Block Scope Usage
  • 5. Let for (var i=0; i<5; i++) { setTimeout( function() { console.log(i); }, 100); } for (var i=0; i<5; i++) { (function (scopedI){ setTimeout( function() { console.log(scopedI); }, 100); })(i); } for (let i=0; i<5; i++) { setTimeout( function() { console.log(i); }, 100); } Avoid Crazy bugs
  • 6.
  • 7. (no) Strings (attached) var name = 'Monika'; console.log('My name is ' + name); let name2 = 'Monika'; console.log(`My name is ${name2}`); var str = 'Template strings providen' + 'syntactic sugar forn' + 'constructing strings.'; let str2 = `Template strings provide syntactic sugar for constructing strings.` Variable Bindings Multiline Strings
  • 8. Strings const headline = 'Yahoo products are beautiful.' headline.startsWith('Yahoo') // true headline.endsWith('beautiful') // true headline.includes('products') // true headline.includes('.') // false headline.repeat(2); //Yahoo products are beautiful.Yahoo products are beautiful. More awesomeness!
  • 9.
  • 10. Arrays var divsArray = [].slice.call(document.querySelectorAll('div')); divsArray.forEach(function(node) { console.log(node); }); let divs = document.querySelectorAll('div'); Array.from(divs).forEach(node => { console.log(node); }); var names = ["Monika", "Seth", "Nikhil", "Mallika"]; var res = names.filter(function (name) { return name === "Monika"; } )[0]; let names2 = ["Monika", "Seth", "Nikhil", "Mallika"]; let res2 = names.find(function (name) { return name === "Monika"; } ); Array like Find one element
  • 11.
  • 12. Function Shorthand var fun = function() { console.log('Yay!') }; let fun2 = () => console.log('Yay!'); var nums = [1,2,3,4,5]; var numsPlus2 = nums.map(function(num) { return num + 2; }); var nums2 = [1,2,3,4,5]; var nums2Plus2 = nums.map(num => num + 2); Usage Awesomeness
  • 13. Function Shorthand this.x = 42; setTimeout( function(){ console.log(this.x); }, 100); this.x = 42; var self = this; setTimeout( function(){ console.log(self.x); }, 100); this.x = 42; setTimeout(() => console.log(this.x), 100); More Awesomeness
  • 14.
  • 15. Function Parameters - default function f(x, y) { if (!y) { y = 1; } return x * y; } function f(x, y) { // y is 12 if not passed (or passed as undefined) if (typeof y === 'undefined') { y = 1; } return x * y; } function f(x, y=1) { return x * y; }
  • 16. Function Parameters - Spread... var nums = [9,10,2]; Math.max(...nums); var nums = [9,10,2]; Math.max(nums); var nums = [9,10,2]; Math.max.apply(null, nums);
  • 17. Function Parameters - Rest... function join(sep, ...nums) { return nums.join(sep); } function join(sep) { var args = [].slice.call(arguments, 1); return args.join(sep); } join(':', 1, 2, 3); join(':', 1, 2);
  • 18.
  • 19. Object (of my affection) - Destructuring const { user, post } = this.props;var user = this.props.user, post = this.props.post; function fun({x, y, z=100}) { return x + y + z; } fun({x:3, y:2}); // 105 function fun(data) { return data.x + data.y; } fun({x:3, y:2}); function fun({x,y}) { return x + y; } fun({x:3, y:2}); Destructuring with default params
  • 20. Objects Literals Extension var obj = { // defining prototype on object creation __proto__: theProtoObj, // shortcut for ‘handler: handler’ handler, // shortcut for methods - 'toString: function() {}' toString() { // base class method call with 'super' return 'd ' + super.toString(); }, // dynamic property names [ 'prop_' + (() => 42)() ]: 42 };
  • 21.
  • 22. (Very) Class(ey) var Shape = function (id, x, y) { this.id = id; this.move(x, y); }; Shape.prototype.move = function (x, y) { this.x = x; this.y = y; }; class Shape { constructor (id, x, y) { this.id = id this.move(x, y) } move (x, y) { this.x = x this.y = y } }
  • 23. Class Inheritance var Rectangle = function (id, x, y, width, height) { Shape.call(this, id, x, y); this.width = width; this.height = height; }; Rectangle.prototype = Object.create(Shape.prototype); Rectangle.prototype.constructor = Rectangle; class Rectangle extends Shape { constructor (id, x, y, width, height) { super(id, x, y) this.width = width this.height = height } }
  • 24.
  • 25. Promise (me, you will come back..) function timeout(duration = 0) { return new Promise((resolve, reject) => { setTimeout(resolve, duration); }) } var p = timeout(1000).then(() => { console.log('Done after 1000 sec'); });
  • 26. var request = require('request'); var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; function foo(finalCallback) { request.get(url1, function(err1, res1) { if (err1) { return finalCallback(err1); } request.post(url2, function(err2, res2) { if (err2) { return finalCallback(err2); } request.put(url3, function(err3, res3) { if (err3) { return finalCallback(err3); } request.del(url4, function(err4, res4) { // let's stop here if (err4) { return finalCallback(err4); } finalCallback(null, "whew all done"); }) }) }) }) } // use that function somewhere foo(function(err, message) { if (err) { return console.log("error!", err); } console.log("success!", message); }); var Promise = require('bluebird'); var request = Promise.promisifyAll(require('request')); var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; function foo() { return request.getAsync(url1) .then(function(res1) { return request.postAsync(url2); }).then(function(res2) { return request.putAsync(url3); }).then(function(res3) { return request.delAsync(url4); }).then(function(res4) { return "whew all done"; }); } // use that function somewhere foo().then(function(message) { console.log("success!", message); }).catch(function(err) { console.log("error!", err); }); Promise
  • 27. var Promise = require('bluebird'); var request = Promise.promisifyAll(require('request')); var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; async function foo() { var res1 = await request.getAsync(url1); var res2 = await request.getAsync(url2); var res3 = await request.getAsync(url3); var res4 = await request.getAsync(url4); return "whew all done"; } // use that function somewhere foo().then(function(message) { console.log("success!", message); }).catch(function(err) { console.log("error!", err); }); Async/ Await - Glimpse
  • 28. So much more.. Modules Proxy Generator, Iterator Maps, Sets Proxy Symbols More...
  • 29.
  • 30. Browser compatible? Javascript compiler Use Next Generation Javascript Today! http://babeljs.io/ Babel Quick Demo Using babel-cli Presets Pubs presets npm install --save-dev babel-cli babel test.js ynpm install --save-dev babel-preset-pubs babel test.js --presets=pubs // Use .babelrc
  • 32. QnA

Hinweis der Redaktion

  1. My favorite part