SlideShare a Scribd company logo
ECMASCRIPT 2015
BEST OF NEW FEATURES().
by / atMiłosz Sobczak @miloszsobczak
Main example source code can be found at github.com/miloszsobczak/es6-rewrite.
CLASSES
CLASSES DEFINITION
ECMASCRIPT 5 OLD WAY
var Developer = function Developer(name, experience, languages) {
this.name(name || '');
this.experience(experience || 0);
this.languages(languages || []);
}
CLASSES DEFINITION
ECMASCRIPT 2015 (6)
class Developer {
constructor (name, experience, languages) {
this.name = name;
this.experience = experience;
this.languages = languages;
}
}
CLASSES INHERITANCE
ECMASCRIPT 5 OLD WAY
var PixersDeveloper = function PixersDeveloper (name, experience, languages,
Developer.call(this, name, experience, languages);
this.awesomeness(awesomeness);
this.worklog = {};
};
PixersDeveloper.prototype = Object.create(Developer.prototype);
PixersDeveloper.prototype.constructor = PixersDeveloper;
PixersDeveloper.prototype.default = function () {
return new PixersDeveloper('Mieszkos', 2, ['Whitespace'], -1000)
}
CLASSES INHERITANCE
ECMASCRIPT 2015 (6)
class PixersDeveloper extends Developer {
constructor (name, experience, languages, awesomeness) {
super(name, experience, languages);
this.awesomeness = awesomeness;
this.Worklog = new Map();
}
}
static default () {
return new PixersDeveloper('Mieszkos', 2, ['Whitespace'], -1000);
}
CLASSES SUPER ACCESS
ECMASCRIPT 5 OLD WAY
//base class constructor
Developer.call(this, name, experience, languages);
//method access
Developer.prototype.method.call(this);
CLASSES SUPER ACCESS
ECMASCRIPT 2015 (6)
//base class constructor
super(name, experience, languages);
//method access
super.method()
CLASSES STATIC FUNCTION
ECMASCRIPT 5 OLD WAY
PixersDeveloper.prototype.default = function () {
return new PixersDeveloper('Mieszkos', 2, ['Whitespace'], -1000)
}
//usage
var Mieszkos = PixersDeveloper.default();
CLASSES STATIC FUNCTION
ECMASCRIPT 2015 (6)
static default () {
return new PixersDeveloper('Mieszkos', 2, ['Whitespace'], -1000);
}
//usage
var Mieszkos = PixersDeveloper.default();
CLASSES SETTER/GETTER
ECMASCRIPT 5 OLD WAY
Described in ecmascript 5.0 (not in 5.1).
PixersDeveloper.prototype.awesomeness = function (value) {
if (typeof value === 'number') {
this._awesomeness = parseInt(value, 10);
}
return this._awesomeness;
}
//setter usage
this.awesomeness(10);
//getter usage
var dev_awesomness = this.awesomeness();
CLASSES SETTER/GETTER
ECMASCRIPT 2015 (6)
set awesomeness (value = 0) {
if (typeof value === 'number') {
this._awesomeness = parseInt(value, 10);
}
}
get awesomeness () {
return this._awesomeness;
}
//setter usage
this.awesomeness = 10;
//getter usage
var dev_awesomness = this.awesomeness;
CLASSES EXTENDING
ECMASCRIPT 5 OLD WAY
BUILT-INS
function MyArray(/*arguments*/) {
var arr = [];
Array.prototype.push.apply(arr, arguments);
copyOwnPropertiesFrom(arr, MyArray.methods);
return arr;
}
var a = new MyArray();
a instanceof MyArray; //false
a instanceof Array; //true
CLASSES EXTENDING BUILT-INS
ECMASCRIPT 2015 (6)
class MyArray extends Array {
constructor(...args) {
super(args);
}
}
//ex below still gives an error, but it shuldn't
class myMath extends Math {}
MODULES
Almost* native module system.
MODULES DEFINITION
REQUIREJS OLD? WAY
define('countPoints', function (){
return function countPoints (langLength, exp) {
var pointPerLanguage = 2,
pointPerExp = 4;
return parseInt(langLength * pointPerLanguage, 10) +
parseInt(exp * pointPerExp, 10);
}
});
//usage
require(['countPoints'], function(countPoints) {
var points = countPoints(2, 5);
});
MODULES DEFINITION
ECMASCRIPT 2015 (6)
export function countPoints (langLength = 0, exp = 0) {
let pointPerLanguage = 2,
pointPerExp = 4;
return parseInt(langLength * pointPerLanguage, 10) +
parseInt(exp * pointPerExp, 10);
}
//usage
import { countPoints } from 'lib/countPoints.js';
points = countPoints(2, 5);
MODULES DEFINITION
ECMASCRIPT 2015 (6) - CAVEATS
IT'S NOT GREAT! (FOR NOW) :)
Support by Mozilla
MODULES DEFINITION
ECMASCRIPT 2015 (6) - CAVEATS
WORKAROUNDS
+ +Browersify babelify Node.js
//basic gulp configuration
var fs = require('fs'),
browserify = require('browserify');
browserify('./script.js')
.transform('babelify')
.bundle()
.pipe(fs.createWriteStream('bundle.js'));
//define
module.exports = function countPoints (langLength = 0, exp = 0) {...}
//use
import countPoints from 'lib/countPoints.js';
BLOCKS && SCOPE VARIABLES
BLOCKS && SCOPE VARIABLES:
CONSTS
ECMASCRIPT 5 OLD WAY
//simple and cross-browser, but still writable
var PI = 3.141593;
//or complicatated and not writable
Object.defineProperty(window, 'PI', {
value: 3.141593,
enumerable: true,
writable: false,
configurable: false
});
BLOCKS && SCOPE VARIABLES:
CONSTS
ECMASCRIPT 2015 (6)
const PI = 3.141593;
const PI = 1; //Uncaught TypeError: Identifier 'PI' has already been declare
var PI = 2; //3.141593
BLOCKS && SCOPE VARIABLES: LET
ECMASCRIPT 5 OLD WAY
var a = 2;
(function own_scope(){
var a = 3;
console.log( a ); // 3
})();
console.log( a ); // 2
BLOCKS && SCOPE VARIABLES: LET
ECMASCRIPT 2015 (6)
var a = 2;
{
let a = 3;
console.log( a ); // 3
}
console.log( a ); // 2
ARROW FUNCTIONS =>
ARROW FUNCTIONS: DEFINITION
ECMASCRIPT 5 OLD WAY
return (function anonymus(points) {
var points = points || 0;
//do something with points
})(countPoints(this.languages().length, this.experience()));
ARROW FUNCTIONS: DEFINITION
ECMASCRIPT 2015 (6)
return ((points = 0) => {
//do something with points
})(countPoints(this.languages.length, this.experience));
ARROW FUNCTIONS: CURRENT
OBJECT CONTEXT
ECMASCRIPT 5 OLD WAY
var self = this;
return (function anonymus(points) {
var points = points || 0;
//do something with points
return self.name() + ' is a Developer';
})(countPoints(this.languages().length, this.experience()));
ARROW FUNCTIONS: CURRENT
OBJECT CONTEXT
ECMASCRIPT 2015 (6)
return ((points = 0) => {
//do something with points
return this.name + ' is a Developer';
})(countPoints(this.languages.length, this.experience));
`${TEMPLATE LITERALS}`
TEMPLATE LITERALS: STRING
INTERPOLATION
ECMASCRIPT 5 OLD WAY
return self.name() + ' is a ' + degree + ' Developer';
TEMPLATE LITERALS: STRING
INTERPOLATION
ECMASCRIPT 2015 (6)
return `${this.name} is a ${degree} Developer`;
NEW DATA STRUCTURE TYPES
1. Key-value collection
Map
WeakMap (object as a key)
2. Values collection
Set
WeakSet (object as a key)
NEW DATA STRUCTURE TYPES: MAP
ECMASCRIPT 5 OLD WAY
this.worklog = {}; //defined in costructor
PixersDeveloper.prototype.setWork = function (taskId, timeInMins) {
var self = this;
if (this.worklog.hasOwnProperty(taskId) === false) {
return this.worklog[taskId] = timeInMins;
}
this.worklog[taskId] = (function () {
return self.getWorkById(taskId) + timeInMins;
})();
}
NEW DATA STRUCTURE TYPES: MAP
ECMASCRIPT 2015 (6)
this.Worklog = new Map(); //defined in costructor
setWork (taskId, timeInMins) {
if (this.Worklog.has(taskId) === false) {
return this.Worklog.set(taskId, timeInMins);
}
this.Worklog.set(taskId, (() => {
let minutes = this.Worklog.get(taskId);
return minutes + timeInMins;
})());
}
THERE IS WAY MUCH MORE...
New built-ins methods...
New literals (binary for example)
Symbol type
Native Promise
...
ECMAScript 5 6 7 intl non-standard compatibility table Fork 201by kangax & webbedspaceGratipay
Please note that some of these tests represent existence, not functionality or full conformance. Sort by number of features? Show obso
unstable platforms?
V8 SpiderMonkey JavaScriptCore Chakra Carakan KJS Other
Minor difference (1 point) Useful feature (2 points) Significant feature (4 points) Landmark feature (8 points)⬤ ⬤ ⬤ ⬤
Compilers/polyfills
►Feature name
Current
browser
74%
Traceur
59%
Babel +
core-js[1]
71%
Closure
30%
JSX[2]
19%
Type-
Script
+
core-js
52%
es6-
shim
17%
IE 10
7%
IE 11
16%
Edge
12[3]
63%
Edge
13[3]
84%
FF 38
ESR
66%
FF
Optimisation
►proper tail calls (tail call optimisation)⬤§ 0/2 0/2 1/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0
Syntax
►default function parameters⬤§ 0/7 4/7 6/7 4/7 0/7 4/7 0/7 0/7 0/7 0/7 0/7 3/7 3
►rest parameters⬤§ 5/5 4/5 4/5 2/5 3/5 3/5 0/5 0/5 0/5 5/5 5/5 4/5 4
►spread (...) operator⬤§ 15/15 15/15 13/15 3/15 2/15 4/15 0/15 0/15 0/15 12/15 15/15 15/15 15
►object literal extensions⬤§ 6/6 6/6 6/6 4/6 5/6 6/6 0/6 0/6 0/6 6/6 6/6 6/6 6
►for..of loops⬤§ 7/9 9/9 9/9 6/9 2/9 3/9 0/9 0/9 0/9 6/9 7/9 7/9 7
►octal and binary literals⬤§ 4/4 2/4 4/4 2/4 0/4 4/4 2/4 0/4 0/4 4/4 4/4 4/4 4
►template strings⬤§ 5/5 4/5 4/5 3/5 4/5 3/5 0/5 0/5 0/5 4/5 5/5 5/5 5
►RegExp "y" and "u" flags⬤§ 0/4 2/4 2/4 0/4 0/4 0/4 0/4 0/4 0/4 2/4 4/4 2/4 2
►destructuring⬤§ 0/37 31/37 34/37 21/37 16/37 26/37 0/37 0/37 0/37 0/37 0/37 28/37 29
►Unicode code point escapes⬤§ 2/2 1/2 1/2 1/2 0/2 1/2 0/2 0/2 0/2 2/2 2/2 0/2 1
►new.target⬤§ 2/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 1/2 0/2 2
Bindings
►const⬤§ 5/8 6/8 6/8 6/8 0/8 6/8 0/8 0/8 8/8 8/8 8/8 8/8 8
►let⬤§ 5/10 8/10 8/10 8/10 0/10 7/10 0/10 0/10 8/10 8/10 8/10 0/10 0/
KANGAX.GITHUB.IO/CO
MPAT-TABLE/ES6
GREAT RESOURCES
exploringjs.com
es6-features.org
developer.mozilla.org
You Don't Know JS: ES6 & Beyond

More Related Content

What's hot

Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
Ismar Silveira
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis Atencio
Luis Atencio
 
Old Oracle Versions
Old Oracle VersionsOld Oracle Versions
Old Oracle Versions
Jeffrey Kemp
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
SpbDotNet Community
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in Python
Colin Su
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
Sumant Tambe
 
Verilog Tasks & Functions
Verilog Tasks & FunctionsVerilog Tasks & Functions
Verilog Tasks & Functions
anand hd
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++
Patrick Viafore
 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
Jussi Pohjolainen
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
Eelco Visser
 
Clear php reference
Clear php referenceClear php reference
Clear php reference
Damien Seguy
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
 
C++11
C++11C++11
Use of Apache Commons and Utilities
Use of Apache Commons and UtilitiesUse of Apache Commons and Utilities
Use of Apache Commons and Utilities
Pramod Kumar
 
C++11
C++11C++11
Debugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsDebugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template Metaprograms
Platonov Sergey
 
High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
Matthieu Garrigues
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
Adam Crabtree
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 Hours
Phillip Trelford
 
Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)
James Titcumb
 

What's hot (20)

Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis Atencio
 
Old Oracle Versions
Old Oracle VersionsOld Oracle Versions
Old Oracle Versions
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in Python
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
Verilog Tasks & Functions
Verilog Tasks & FunctionsVerilog Tasks & Functions
Verilog Tasks & Functions
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++
 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
 
Clear php reference
Clear php referenceClear php reference
Clear php reference
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
C++11
C++11C++11
C++11
 
Use of Apache Commons and Utilities
Use of Apache Commons and UtilitiesUse of Apache Commons and Utilities
Use of Apache Commons and Utilities
 
C++11
C++11C++11
C++11
 
Debugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsDebugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template Metaprograms
 
High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 Hours
 
Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)
 

Similar to Ecmascript 2015 – best of new features()

Workshop JavaScript ES6+
Workshop JavaScript ES6+Workshop JavaScript ES6+
Workshop JavaScript ES6+
Roy Derks
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
Justin Alexander
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
qmmr
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
Jarrod Overson
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 Simplified
Carlos Ble
 
Kpi driven-java-development-fn conf
Kpi driven-java-development-fn confKpi driven-java-development-fn conf
Kpi driven-java-development-fn conf
Anirban Bhattacharjee
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009
tolmasky
 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
Right IT Services
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
François Sarradin
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
Damien Seguy
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
Visual Engineering
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
Christoffer Noring
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
Sperasoft
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
ManageIQ
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
Leo Hernandez
 
Node.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizationsNode.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizations
Dawid Rusnak
 
PHP7 Presentation
PHP7 PresentationPHP7 Presentation
PHP7 Presentation
David Sanchez
 
Painless Javascript Unit Testing
Painless Javascript Unit TestingPainless Javascript Unit Testing
Painless Javascript Unit Testing
Benjamin Wilson
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
Wim Godden
 

Similar to Ecmascript 2015 – best of new features() (20)

Workshop JavaScript ES6+
Workshop JavaScript ES6+Workshop JavaScript ES6+
Workshop JavaScript ES6+
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 Simplified
 
Kpi driven-java-development-fn conf
Kpi driven-java-development-fn confKpi driven-java-development-fn conf
Kpi driven-java-development-fn conf
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009
 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
Node.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizationsNode.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizations
 
PHP7 Presentation
PHP7 PresentationPHP7 Presentation
PHP7 Presentation
 
Painless Javascript Unit Testing
Painless Javascript Unit TestingPainless Javascript Unit Testing
Painless Javascript Unit Testing
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
 

Recently uploaded

GUIA_LEGAL_CHAPTER_4_FOREIGN TRADE CUSTOMS.pdf
GUIA_LEGAL_CHAPTER_4_FOREIGN TRADE CUSTOMS.pdfGUIA_LEGAL_CHAPTER_4_FOREIGN TRADE CUSTOMS.pdf
GUIA_LEGAL_CHAPTER_4_FOREIGN TRADE CUSTOMS.pdf
ProexportColombia1
 
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model SafeBangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
bookhotbebes1
 
Understanding Cybersecurity Breaches: Causes, Consequences, and Prevention
Understanding Cybersecurity Breaches: Causes, Consequences, and PreventionUnderstanding Cybersecurity Breaches: Causes, Consequences, and Prevention
Understanding Cybersecurity Breaches: Causes, Consequences, and Prevention
Bert Blevins
 
L-3536-Cost Benifit Analysis in ESIA.pptx
L-3536-Cost Benifit Analysis in ESIA.pptxL-3536-Cost Benifit Analysis in ESIA.pptx
L-3536-Cost Benifit Analysis in ESIA.pptx
naseki5964
 
Rohini @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Yogita Mehra Top Model Safe
Rohini @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Yogita Mehra Top Model SafeRohini @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Yogita Mehra Top Model Safe
Rohini @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Yogita Mehra Top Model Safe
binna singh$A17
 
SCADAmetrics Instrumentation for Sensus Water Meters - Core and Main Training...
SCADAmetrics Instrumentation for Sensus Water Meters - Core and Main Training...SCADAmetrics Instrumentation for Sensus Water Meters - Core and Main Training...
SCADAmetrics Instrumentation for Sensus Water Meters - Core and Main Training...
Jim Mimlitz, P.E.
 
Vernier Caliper and How to use Vernier Caliper.ppsx
Vernier Caliper and How to use Vernier Caliper.ppsxVernier Caliper and How to use Vernier Caliper.ppsx
Vernier Caliper and How to use Vernier Caliper.ppsx
Tool and Die Tech
 
Unblocking The Main Thread - Solving ANRs and Frozen Frames
Unblocking The Main Thread - Solving ANRs and Frozen FramesUnblocking The Main Thread - Solving ANRs and Frozen Frames
Unblocking The Main Thread - Solving ANRs and Frozen Frames
Sinan KOZAK
 
IS Code SP 23: Handbook on concrete mixes
IS Code SP 23: Handbook  on concrete mixesIS Code SP 23: Handbook  on concrete mixes
IS Code SP 23: Handbook on concrete mixes
Mani Krishna Sarkar
 
Germany Offshore Wind 010724 RE (1) 2 test.pptx
Germany Offshore Wind 010724 RE (1) 2 test.pptxGermany Offshore Wind 010724 RE (1) 2 test.pptx
Germany Offshore Wind 010724 RE (1) 2 test.pptx
rebecca841358
 
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE DonatoCONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
Servizi a rete
 
1239_2.pdf IS CODE FOR GI PIPE FOR PROCUREMENT
1239_2.pdf IS CODE FOR GI PIPE FOR PROCUREMENT1239_2.pdf IS CODE FOR GI PIPE FOR PROCUREMENT
1239_2.pdf IS CODE FOR GI PIPE FOR PROCUREMENT
Mani Krishna Sarkar
 
Chlorine and Nitric Acid application, properties, impacts.pptx
Chlorine and Nitric Acid application, properties, impacts.pptxChlorine and Nitric Acid application, properties, impacts.pptx
Chlorine and Nitric Acid application, properties, impacts.pptx
yadavsuyash008
 
IWISS Catalog 2024
IWISS Catalog 2024IWISS Catalog 2024
IWISS Catalog 2024
Iwiss Tools Co.,Ltd
 
Quadcopter Dynamics, Stability and Control
Quadcopter Dynamics, Stability and ControlQuadcopter Dynamics, Stability and Control
Quadcopter Dynamics, Stability and Control
Blesson Easo Varghese
 
Exploring Deep Learning Models for Image Recognition: A Comparative Review
Exploring Deep Learning Models for Image Recognition: A Comparative ReviewExploring Deep Learning Models for Image Recognition: A Comparative Review
Exploring Deep Learning Models for Image Recognition: A Comparative Review
sipij
 
Paharganj @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Arti Singh Top Model Safe
Paharganj @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Arti Singh Top Model SafePaharganj @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Arti Singh Top Model Safe
Paharganj @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Arti Singh Top Model Safe
aarusi sexy model
 
Introduction to IP address concept - Computer Networking
Introduction to IP address concept - Computer NetworkingIntroduction to IP address concept - Computer Networking
Introduction to IP address concept - Computer Networking
Md.Shohel Rana ( M.Sc in CSE Khulna University of Engineering & Technology (KUET))
 
Advances in Detect and Avoid for Unmanned Aircraft Systems and Advanced Air M...
Advances in Detect and Avoid for Unmanned Aircraft Systems and Advanced Air M...Advances in Detect and Avoid for Unmanned Aircraft Systems and Advanced Air M...
Advances in Detect and Avoid for Unmanned Aircraft Systems and Advanced Air M...
VICTOR MAESTRE RAMIREZ
 
Conservation of Taksar through Economic Regeneration
Conservation of Taksar through Economic RegenerationConservation of Taksar through Economic Regeneration
Conservation of Taksar through Economic Regeneration
PriyankaKarn3
 

Recently uploaded (20)

GUIA_LEGAL_CHAPTER_4_FOREIGN TRADE CUSTOMS.pdf
GUIA_LEGAL_CHAPTER_4_FOREIGN TRADE CUSTOMS.pdfGUIA_LEGAL_CHAPTER_4_FOREIGN TRADE CUSTOMS.pdf
GUIA_LEGAL_CHAPTER_4_FOREIGN TRADE CUSTOMS.pdf
 
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model SafeBangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Bangalore @ℂall @Girls ꧁❤ 0000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
 
Understanding Cybersecurity Breaches: Causes, Consequences, and Prevention
Understanding Cybersecurity Breaches: Causes, Consequences, and PreventionUnderstanding Cybersecurity Breaches: Causes, Consequences, and Prevention
Understanding Cybersecurity Breaches: Causes, Consequences, and Prevention
 
L-3536-Cost Benifit Analysis in ESIA.pptx
L-3536-Cost Benifit Analysis in ESIA.pptxL-3536-Cost Benifit Analysis in ESIA.pptx
L-3536-Cost Benifit Analysis in ESIA.pptx
 
Rohini @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Yogita Mehra Top Model Safe
Rohini @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Yogita Mehra Top Model SafeRohini @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Yogita Mehra Top Model Safe
Rohini @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Yogita Mehra Top Model Safe
 
SCADAmetrics Instrumentation for Sensus Water Meters - Core and Main Training...
SCADAmetrics Instrumentation for Sensus Water Meters - Core and Main Training...SCADAmetrics Instrumentation for Sensus Water Meters - Core and Main Training...
SCADAmetrics Instrumentation for Sensus Water Meters - Core and Main Training...
 
Vernier Caliper and How to use Vernier Caliper.ppsx
Vernier Caliper and How to use Vernier Caliper.ppsxVernier Caliper and How to use Vernier Caliper.ppsx
Vernier Caliper and How to use Vernier Caliper.ppsx
 
Unblocking The Main Thread - Solving ANRs and Frozen Frames
Unblocking The Main Thread - Solving ANRs and Frozen FramesUnblocking The Main Thread - Solving ANRs and Frozen Frames
Unblocking The Main Thread - Solving ANRs and Frozen Frames
 
IS Code SP 23: Handbook on concrete mixes
IS Code SP 23: Handbook  on concrete mixesIS Code SP 23: Handbook  on concrete mixes
IS Code SP 23: Handbook on concrete mixes
 
Germany Offshore Wind 010724 RE (1) 2 test.pptx
Germany Offshore Wind 010724 RE (1) 2 test.pptxGermany Offshore Wind 010724 RE (1) 2 test.pptx
Germany Offshore Wind 010724 RE (1) 2 test.pptx
 
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE DonatoCONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
CONVEGNO DA IRETI 18 giugno 2024 | PASQUALE Donato
 
1239_2.pdf IS CODE FOR GI PIPE FOR PROCUREMENT
1239_2.pdf IS CODE FOR GI PIPE FOR PROCUREMENT1239_2.pdf IS CODE FOR GI PIPE FOR PROCUREMENT
1239_2.pdf IS CODE FOR GI PIPE FOR PROCUREMENT
 
Chlorine and Nitric Acid application, properties, impacts.pptx
Chlorine and Nitric Acid application, properties, impacts.pptxChlorine and Nitric Acid application, properties, impacts.pptx
Chlorine and Nitric Acid application, properties, impacts.pptx
 
IWISS Catalog 2024
IWISS Catalog 2024IWISS Catalog 2024
IWISS Catalog 2024
 
Quadcopter Dynamics, Stability and Control
Quadcopter Dynamics, Stability and ControlQuadcopter Dynamics, Stability and Control
Quadcopter Dynamics, Stability and Control
 
Exploring Deep Learning Models for Image Recognition: A Comparative Review
Exploring Deep Learning Models for Image Recognition: A Comparative ReviewExploring Deep Learning Models for Image Recognition: A Comparative Review
Exploring Deep Learning Models for Image Recognition: A Comparative Review
 
Paharganj @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Arti Singh Top Model Safe
Paharganj @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Arti Singh Top Model SafePaharganj @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Arti Singh Top Model Safe
Paharganj @ℂall @Girls ꧁❤ 9873777170 ❤꧂VIP Arti Singh Top Model Safe
 
Introduction to IP address concept - Computer Networking
Introduction to IP address concept - Computer NetworkingIntroduction to IP address concept - Computer Networking
Introduction to IP address concept - Computer Networking
 
Advances in Detect and Avoid for Unmanned Aircraft Systems and Advanced Air M...
Advances in Detect and Avoid for Unmanned Aircraft Systems and Advanced Air M...Advances in Detect and Avoid for Unmanned Aircraft Systems and Advanced Air M...
Advances in Detect and Avoid for Unmanned Aircraft Systems and Advanced Air M...
 
Conservation of Taksar through Economic Regeneration
Conservation of Taksar through Economic RegenerationConservation of Taksar through Economic Regeneration
Conservation of Taksar through Economic Regeneration
 

Ecmascript 2015 – best of new features()

  • 1. ECMASCRIPT 2015 BEST OF NEW FEATURES(). by / atMiłosz Sobczak @miloszsobczak Main example source code can be found at github.com/miloszsobczak/es6-rewrite.
  • 3. CLASSES DEFINITION ECMASCRIPT 5 OLD WAY var Developer = function Developer(name, experience, languages) { this.name(name || ''); this.experience(experience || 0); this.languages(languages || []); }
  • 4. CLASSES DEFINITION ECMASCRIPT 2015 (6) class Developer { constructor (name, experience, languages) { this.name = name; this.experience = experience; this.languages = languages; } }
  • 5. CLASSES INHERITANCE ECMASCRIPT 5 OLD WAY var PixersDeveloper = function PixersDeveloper (name, experience, languages, Developer.call(this, name, experience, languages); this.awesomeness(awesomeness); this.worklog = {}; }; PixersDeveloper.prototype = Object.create(Developer.prototype); PixersDeveloper.prototype.constructor = PixersDeveloper; PixersDeveloper.prototype.default = function () { return new PixersDeveloper('Mieszkos', 2, ['Whitespace'], -1000) }
  • 6. CLASSES INHERITANCE ECMASCRIPT 2015 (6) class PixersDeveloper extends Developer { constructor (name, experience, languages, awesomeness) { super(name, experience, languages); this.awesomeness = awesomeness; this.Worklog = new Map(); } } static default () { return new PixersDeveloper('Mieszkos', 2, ['Whitespace'], -1000); }
  • 7. CLASSES SUPER ACCESS ECMASCRIPT 5 OLD WAY //base class constructor Developer.call(this, name, experience, languages); //method access Developer.prototype.method.call(this);
  • 8. CLASSES SUPER ACCESS ECMASCRIPT 2015 (6) //base class constructor super(name, experience, languages); //method access super.method()
  • 9. CLASSES STATIC FUNCTION ECMASCRIPT 5 OLD WAY PixersDeveloper.prototype.default = function () { return new PixersDeveloper('Mieszkos', 2, ['Whitespace'], -1000) } //usage var Mieszkos = PixersDeveloper.default();
  • 10. CLASSES STATIC FUNCTION ECMASCRIPT 2015 (6) static default () { return new PixersDeveloper('Mieszkos', 2, ['Whitespace'], -1000); } //usage var Mieszkos = PixersDeveloper.default();
  • 11. CLASSES SETTER/GETTER ECMASCRIPT 5 OLD WAY Described in ecmascript 5.0 (not in 5.1). PixersDeveloper.prototype.awesomeness = function (value) { if (typeof value === 'number') { this._awesomeness = parseInt(value, 10); } return this._awesomeness; } //setter usage this.awesomeness(10); //getter usage var dev_awesomness = this.awesomeness();
  • 12. CLASSES SETTER/GETTER ECMASCRIPT 2015 (6) set awesomeness (value = 0) { if (typeof value === 'number') { this._awesomeness = parseInt(value, 10); } } get awesomeness () { return this._awesomeness; } //setter usage this.awesomeness = 10; //getter usage var dev_awesomness = this.awesomeness;
  • 13. CLASSES EXTENDING ECMASCRIPT 5 OLD WAY BUILT-INS function MyArray(/*arguments*/) { var arr = []; Array.prototype.push.apply(arr, arguments); copyOwnPropertiesFrom(arr, MyArray.methods); return arr; } var a = new MyArray(); a instanceof MyArray; //false a instanceof Array; //true
  • 14. CLASSES EXTENDING BUILT-INS ECMASCRIPT 2015 (6) class MyArray extends Array { constructor(...args) { super(args); } } //ex below still gives an error, but it shuldn't class myMath extends Math {}
  • 16. MODULES DEFINITION REQUIREJS OLD? WAY define('countPoints', function (){ return function countPoints (langLength, exp) { var pointPerLanguage = 2, pointPerExp = 4; return parseInt(langLength * pointPerLanguage, 10) + parseInt(exp * pointPerExp, 10); } }); //usage require(['countPoints'], function(countPoints) { var points = countPoints(2, 5); });
  • 17. MODULES DEFINITION ECMASCRIPT 2015 (6) export function countPoints (langLength = 0, exp = 0) { let pointPerLanguage = 2, pointPerExp = 4; return parseInt(langLength * pointPerLanguage, 10) + parseInt(exp * pointPerExp, 10); } //usage import { countPoints } from 'lib/countPoints.js'; points = countPoints(2, 5);
  • 18. MODULES DEFINITION ECMASCRIPT 2015 (6) - CAVEATS IT'S NOT GREAT! (FOR NOW) :) Support by Mozilla
  • 19. MODULES DEFINITION ECMASCRIPT 2015 (6) - CAVEATS WORKAROUNDS + +Browersify babelify Node.js //basic gulp configuration var fs = require('fs'), browserify = require('browserify'); browserify('./script.js') .transform('babelify') .bundle() .pipe(fs.createWriteStream('bundle.js')); //define module.exports = function countPoints (langLength = 0, exp = 0) {...} //use import countPoints from 'lib/countPoints.js';
  • 20. BLOCKS && SCOPE VARIABLES
  • 21. BLOCKS && SCOPE VARIABLES: CONSTS ECMASCRIPT 5 OLD WAY //simple and cross-browser, but still writable var PI = 3.141593; //or complicatated and not writable Object.defineProperty(window, 'PI', { value: 3.141593, enumerable: true, writable: false, configurable: false });
  • 22. BLOCKS && SCOPE VARIABLES: CONSTS ECMASCRIPT 2015 (6) const PI = 3.141593; const PI = 1; //Uncaught TypeError: Identifier 'PI' has already been declare var PI = 2; //3.141593
  • 23. BLOCKS && SCOPE VARIABLES: LET ECMASCRIPT 5 OLD WAY var a = 2; (function own_scope(){ var a = 3; console.log( a ); // 3 })(); console.log( a ); // 2
  • 24. BLOCKS && SCOPE VARIABLES: LET ECMASCRIPT 2015 (6) var a = 2; { let a = 3; console.log( a ); // 3 } console.log( a ); // 2
  • 26. ARROW FUNCTIONS: DEFINITION ECMASCRIPT 5 OLD WAY return (function anonymus(points) { var points = points || 0; //do something with points })(countPoints(this.languages().length, this.experience()));
  • 27. ARROW FUNCTIONS: DEFINITION ECMASCRIPT 2015 (6) return ((points = 0) => { //do something with points })(countPoints(this.languages.length, this.experience));
  • 28. ARROW FUNCTIONS: CURRENT OBJECT CONTEXT ECMASCRIPT 5 OLD WAY var self = this; return (function anonymus(points) { var points = points || 0; //do something with points return self.name() + ' is a Developer'; })(countPoints(this.languages().length, this.experience()));
  • 29. ARROW FUNCTIONS: CURRENT OBJECT CONTEXT ECMASCRIPT 2015 (6) return ((points = 0) => { //do something with points return this.name + ' is a Developer'; })(countPoints(this.languages.length, this.experience));
  • 31. TEMPLATE LITERALS: STRING INTERPOLATION ECMASCRIPT 5 OLD WAY return self.name() + ' is a ' + degree + ' Developer';
  • 32. TEMPLATE LITERALS: STRING INTERPOLATION ECMASCRIPT 2015 (6) return `${this.name} is a ${degree} Developer`;
  • 33. NEW DATA STRUCTURE TYPES 1. Key-value collection Map WeakMap (object as a key) 2. Values collection Set WeakSet (object as a key)
  • 34. NEW DATA STRUCTURE TYPES: MAP ECMASCRIPT 5 OLD WAY this.worklog = {}; //defined in costructor PixersDeveloper.prototype.setWork = function (taskId, timeInMins) { var self = this; if (this.worklog.hasOwnProperty(taskId) === false) { return this.worklog[taskId] = timeInMins; } this.worklog[taskId] = (function () { return self.getWorkById(taskId) + timeInMins; })(); }
  • 35. NEW DATA STRUCTURE TYPES: MAP ECMASCRIPT 2015 (6) this.Worklog = new Map(); //defined in costructor setWork (taskId, timeInMins) { if (this.Worklog.has(taskId) === false) { return this.Worklog.set(taskId, timeInMins); } this.Worklog.set(taskId, (() => { let minutes = this.Worklog.get(taskId); return minutes + timeInMins; })()); }
  • 36. THERE IS WAY MUCH MORE... New built-ins methods... New literals (binary for example) Symbol type Native Promise ...
  • 37. ECMAScript 5 6 7 intl non-standard compatibility table Fork 201by kangax & webbedspaceGratipay Please note that some of these tests represent existence, not functionality or full conformance. Sort by number of features? Show obso unstable platforms? V8 SpiderMonkey JavaScriptCore Chakra Carakan KJS Other Minor difference (1 point) Useful feature (2 points) Significant feature (4 points) Landmark feature (8 points)⬤ ⬤ ⬤ ⬤ Compilers/polyfills ►Feature name Current browser 74% Traceur 59% Babel + core-js[1] 71% Closure 30% JSX[2] 19% Type- Script + core-js 52% es6- shim 17% IE 10 7% IE 11 16% Edge 12[3] 63% Edge 13[3] 84% FF 38 ESR 66% FF Optimisation ►proper tail calls (tail call optimisation)⬤§ 0/2 0/2 1/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0 Syntax ►default function parameters⬤§ 0/7 4/7 6/7 4/7 0/7 4/7 0/7 0/7 0/7 0/7 0/7 3/7 3 ►rest parameters⬤§ 5/5 4/5 4/5 2/5 3/5 3/5 0/5 0/5 0/5 5/5 5/5 4/5 4 ►spread (...) operator⬤§ 15/15 15/15 13/15 3/15 2/15 4/15 0/15 0/15 0/15 12/15 15/15 15/15 15 ►object literal extensions⬤§ 6/6 6/6 6/6 4/6 5/6 6/6 0/6 0/6 0/6 6/6 6/6 6/6 6 ►for..of loops⬤§ 7/9 9/9 9/9 6/9 2/9 3/9 0/9 0/9 0/9 6/9 7/9 7/9 7 ►octal and binary literals⬤§ 4/4 2/4 4/4 2/4 0/4 4/4 2/4 0/4 0/4 4/4 4/4 4/4 4 ►template strings⬤§ 5/5 4/5 4/5 3/5 4/5 3/5 0/5 0/5 0/5 4/5 5/5 5/5 5 ►RegExp "y" and "u" flags⬤§ 0/4 2/4 2/4 0/4 0/4 0/4 0/4 0/4 0/4 2/4 4/4 2/4 2 ►destructuring⬤§ 0/37 31/37 34/37 21/37 16/37 26/37 0/37 0/37 0/37 0/37 0/37 28/37 29 ►Unicode code point escapes⬤§ 2/2 1/2 1/2 1/2 0/2 1/2 0/2 0/2 0/2 2/2 2/2 0/2 1 ►new.target⬤§ 2/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 0/2 1/2 0/2 2 Bindings ►const⬤§ 5/8 6/8 6/8 6/8 0/8 6/8 0/8 0/8 8/8 8/8 8/8 8/8 8 ►let⬤§ 5/10 8/10 8/10 8/10 0/10 7/10 0/10 0/10 8/10 8/10 8/10 0/10 0/ KANGAX.GITHUB.IO/CO MPAT-TABLE/ES6