SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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 #4Ismar 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 AtencioLuis Atencio
 
Old Oracle Versions
Old Oracle VersionsOld Oracle Versions
Old Oracle VersionsJeffrey Kemp
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»SpbDotNet Community
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in PythonColin 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 & Functionsanand hd
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++Patrick Viafore
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with StatixEelco Visser
 
Clear php reference
Clear php referenceClear php reference
Clear php referenceDamien Seguy
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Scott Wlaschin
 
Use of Apache Commons and Utilities
Use of Apache Commons and UtilitiesUse of Apache Commons and Utilities
Use of Apache Commons and UtilitiesPramod Kumar
 
Debugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsDebugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsPlatonov 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++14Matthieu Garrigues
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: FunctionsAdam 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 HoursPhillip 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
 

Mais procurados (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)
 

Semelhante a Ecmascript 2015 – best of new features()

Workshop JavaScript ES6+
Workshop JavaScript ES6+Workshop JavaScript ES6+
Workshop JavaScript ES6+Roy Derks
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015qmmr
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 SimplifiedCarlos Ble
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009tolmasky
 
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
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
 
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 PovolnyManageIQ
 
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 optimizationsDawid Rusnak
 
Painless Javascript Unit Testing
Painless Javascript Unit TestingPainless Javascript Unit Testing
Painless Javascript Unit TestingBenjamin 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.5Wim Godden
 

Semelhante a 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
 

Último

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Último (20)

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

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