SlideShare a Scribd company logo
"When all you have is a
hammer
every problem looks like a nail"
Abraham Maslow 1966
ben@mobz.org
name
web site
twitter / github
email
Modularity
Isolation
Virtualisation Language
Reform
Tool / Lib
Enabling
Versioning
Control
Effects
Draft 6th Edition Rev 24 (2014-04-27)
Isolation
Virtualisation Language
Reform
Control
Effects
Recap
but first…
Object
• An Associative Array
• maps string ➝ anything
• prototypical inheritance
var obj = new Object();
var obj = {};
// setting a value
obj[ "key1" ] = "value1";
obj[ "key2" ] = window.document;
obj[ "key3" ] = null
// getting a value
obj[ "key1" ]; // returns "value1"
obj[ "toString" ]; // returns a function
// iterating over keys
for( key in obj ) {
console.log( key, obj[ key ] );
}
// maybe we should do this?
for( key in obj ) {
if( Object.prototype.hasOwnProperty.call( obj, key ) ) {
console.log( key, obj[ key ] );
}
}
Is it for
inheritance?
Is it a data structure?
Well…
we have both, and
it's not so great
DON'T WORRY GUYS...
DATA CONTROL IS HERE
Array
• You know them, you love them
• maps number ➝ anything
• plus magical length property
var arr = new Array();
var arr = [];
// constructing with the from method
var imgs = Array.from( document.querySelectorAll( "IMG" ) );
var args = Array.from( arguments );
// with the spread operator
var imgs = [ ...document.querySelectorAll( "IMG" ) ];
var args = [ ...arguments ];
arr[0] = "value1";
arr[1] = new Anything();
arr.push( "value3" );
arr.slice; // etc
arr[1]; // returns [object Anything]
arr.pop(); // returns "value3"
arr.indexOf( "value1" ); // returns 0
arr.length; // returns 2
for( let i = 0; i < arr.length; i++ ) {
console.log( i, arr[i] );
}
arr.forEach( fn );
arr.map( fn );
Set
• List of unique values
• no duplicates allowed
• does not map / associate with anything
var set = new Set();
set.add( "key" );
set.add( 208 );
set.add( { name: "Schrödinger's Cat", alive: undefined } );
set.add( window.document );
set.add( NaN );
var set = new Set();
var ann = { name: "Ann" };
var bob = { name: "Bob" };
set.add( ann );
set.add( bob );
set.has( ann ); // true
set.add( ann );
set.size; // returns 2
set.delete( ann );
set.size; // returns 1
Map
• An associative array
• maps anything ➝ anything
var map = new Map();
map.set( "key1", "value1" );
map.set( null, "value2 );
map.set( window.document, function() { return true; } );
map.size; // returns 3
map.get( "key1" ); // returns "value1"
map.get( null ); // returns "value2"
map.delete( window.document );
map.clear();
var ann = { name: "Ann" };
var bob = { name: "Bob" };
var age = new Map();
age.set( ann, 45 );
age.set( bob, 27 );
age.get( bob ); // returns 27
WeakMap
• Similar to Map
• References to keys are weakly held
• Maps objects ➝ anything
• Does not have a determined size
var handlers = new Map();
[ "ryanseddon", "paul_irish" ].forEach( function( name ) {
var node = generateAvatarComponent( name );
handlers.set( node, showProfile );
parent.appendChild( node );
});
parent.remove();
// handlers contains 2 items
// you have a memory leak
var handlers = new WeakMap();
[ "ryanseddon", "paul_irish" ].forEach( function( name ) {
var node = generateAvatarComponent( name );
handlers.set( node, showProfile );
parent.appendChild( node );
});
parent.remove();
// handlers is empty
// no leaks!
WeakSet
• Weak version of Set
• fairly limited use cases
Iterators
• An iterable lets you iterate over a list of values
• An object that contains a next() method
• returns an object containing { done, value }
• Create Iterators from Array, Map and Set
• Can NOT iterator over WeakMap and WeakSet
var array = [ "a", "b", "c" ];
var iterator = array.entries();
iterator.next(); // returns { done: false, value: [ 0, "a" ] }
iterator.next(); // returns { done: false, value: [ 1, "b" ] }
iterator.next(); // returns { done: false, value: [ 2, "c" ] }
iterator.next(); // returns { done: true, value: undefined }
// with for of and destructuring
for( var [ index, value ] of array.entries() ) {
console.log( index, value );
}
// compare
for( let index = 0; index < array.length; index++ ) {
console.log( index, array[ index ] );
}
new Array( iterable );
new Map( iterable );
new Set( iterable );
array.entries(); // iterator returns [ index, value ]
array.keys(); // iterator returns index
array.values(); // iterator returns value
map.entries(); // iterator returns [ key, value ]
map.keys(); // iterator returns key
map.values(); // iterator returns value
set.entries(); // iterator returns [ key, key ]
set.keys(); // iterator returns key
set.values(); // iterator returns key
Key Type
Prototype
conflict
JSON Iterable
Weak
References
size
Object String Yes Yes No No No*
Array Index No* Yes Yes No length
Map Anything No No Yes No size
Set Anything No No Yes No size
WeakMap Object No No No Yes No
WeakSet Object No No No Yes No
Firefox IE11 Chrome1 Node2
Map / Set Yes Yes Yes Yes
WeakMap / WeakSet Yes WeakMap only Yes Yes
Iterables Non-conforming No Non-conforming No
Destructuring Yes No No No
Spread Yes No No No
1 requires enabling "experimental features"
2 requires running with the --harmony flag
ben@mobz.org
name
web site
twitter / github
email
This is the end

More Related Content

PDF
What they don't tell you about JavaScript
Raphael Cruzeiro
 
PDF
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
 
PDF
RxJS Evolved
trxcllnt
 
PDF
Mozilla とブラウザゲーム
Noritada Shimizu
 
PDF
Cycle.js: Functional and Reactive
Eugene Zharkov
 
PDF
Javascript ES6 generators
RameshNair6
 
KEY
Object-Oriented Javascript
kvangork
 
PPTX
ES6 in Real Life
Domenic Denicola
 
What they don't tell you about JavaScript
Raphael Cruzeiro
 
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
 
RxJS Evolved
trxcllnt
 
Mozilla とブラウザゲーム
Noritada Shimizu
 
Cycle.js: Functional and Reactive
Eugene Zharkov
 
Javascript ES6 generators
RameshNair6
 
Object-Oriented Javascript
kvangork
 
ES6 in Real Life
Domenic Denicola
 

What's hot (19)

PDF
AJUG April 2011 Raw hadoop example
Christopher Curtin
 
PDF
Elm: give it a try
Eugene Zharkov
 
PPTX
ES6 Overview
Bruno Scopelliti
 
PPTX
Angular2 rxjs
Christoffer Noring
 
PDF
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
PDF
Scaling up data science applications
Kexin Xie
 
PDF
EcmaScript 6 - The future is here
Sebastiano Armeli
 
DOCX
ts
CHEN Qingjun
 
PDF
rx.js make async programming simpler
Alexander Mostovenko
 
PDF
"PostgreSQL and Python" Lightning Talk @EuroPython2014
Henning Jacobs
 
PDF
RxJS 5 in Depth
C4Media
 
PDF
Explaining ES6: JavaScript History and What is to Come
Cory Forsyth
 
PPT
Gearmam, from the_worker's_perspective copy
Brian Aker
 
PDF
Wprowadzenie do technologi Big Data i Apache Hadoop
Sages
 
PDF
Introduction to cron queue
ADCI Solutions
 
PDF
Gearman, from the worker's perspective
Brian Aker
 
PPTX
Fact, Fiction, and FP
Brian Lonsdorf
 
PPTX
Ricky Bobby's World
Brian Lonsdorf
 
PDF
Python postgre sql a wonderful wedding
Stéphane Wirtel
 
AJUG April 2011 Raw hadoop example
Christopher Curtin
 
Elm: give it a try
Eugene Zharkov
 
ES6 Overview
Bruno Scopelliti
 
Angular2 rxjs
Christoffer Noring
 
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
Scaling up data science applications
Kexin Xie
 
EcmaScript 6 - The future is here
Sebastiano Armeli
 
rx.js make async programming simpler
Alexander Mostovenko
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
Henning Jacobs
 
RxJS 5 in Depth
C4Media
 
Explaining ES6: JavaScript History and What is to Come
Cory Forsyth
 
Gearmam, from the_worker's_perspective copy
Brian Aker
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Sages
 
Introduction to cron queue
ADCI Solutions
 
Gearman, from the worker's perspective
Brian Aker
 
Fact, Fiction, and FP
Brian Lonsdorf
 
Ricky Bobby's World
Brian Lonsdorf
 
Python postgre sql a wonderful wedding
Stéphane Wirtel
 
Ad

Similar to Data Types and Processing in ES6 (20)

PDF
Mastering The Collections in JavaScript [Free Meetup]
Haim Michael
 
PDF
MCS First Year JavaScript ES6 Features.pdf
KavitaSawant18
 
PDF
ES6: The future is now
Sebastiano Armeli
 
PDF
New collections in JS: Map, Set, WeakMap, WeakSet - WarsawJS Meetup #25
Piotr Kowalski
 
PDF
Underscore.js
timourian
 
PPTX
8558537werr.pptx
ssuser8a9aac
 
PPTX
12. Map | WeakMap | ES6 | JavaScript | Typescript
pcnmtutorials
 
PPTX
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
PDF
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
PPTX
Things you can do in JavaScript ES6 that can't be done in ES5
Dan Shappir
 
PPTX
Introduction to es6
NexThoughts Technologies
 
KEY
Underscore.js
Kevin Ball
 
PDF
JavaScript 1.8.5: New Features Explored
☆ Milan Adamovsky ☆
 
PDF
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
 
PDF
Data Structures in javaScript 2015
Nir Kaufman
 
PDF
Immutable js reactmeetup_local_ppt
Christiane (Tina) Heiligers
 
PPT
Intermediate JavaScript
☆ Milan Adamovsky ☆
 
PPTX
A Skeptics guide to functional style javascript
jonathanfmills
 
PPTX
ECMA5 and ES6 Promises
Oswald Campesato
 
PPTX
What’s new in ECMAScript 6.0
Eyal Vardi
 
Mastering The Collections in JavaScript [Free Meetup]
Haim Michael
 
MCS First Year JavaScript ES6 Features.pdf
KavitaSawant18
 
ES6: The future is now
Sebastiano Armeli
 
New collections in JS: Map, Set, WeakMap, WeakSet - WarsawJS Meetup #25
Piotr Kowalski
 
Underscore.js
timourian
 
8558537werr.pptx
ssuser8a9aac
 
12. Map | WeakMap | ES6 | JavaScript | Typescript
pcnmtutorials
 
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
Things you can do in JavaScript ES6 that can't be done in ES5
Dan Shappir
 
Introduction to es6
NexThoughts Technologies
 
Underscore.js
Kevin Ball
 
JavaScript 1.8.5: New Features Explored
☆ Milan Adamovsky ☆
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
 
Data Structures in javaScript 2015
Nir Kaufman
 
Immutable js reactmeetup_local_ppt
Christiane (Tina) Heiligers
 
Intermediate JavaScript
☆ Milan Adamovsky ☆
 
A Skeptics guide to functional style javascript
jonathanfmills
 
ECMA5 and ES6 Promises
Oswald Campesato
 
What’s new in ECMAScript 6.0
Eyal Vardi
 
Ad

Recently uploaded (20)

PPTX
AIRLINE PRICE API | FLIGHT API COST |
philipnathen82
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Tier1 app
 
PPTX
Benefits of DCCM for Genesys Contact Center
pointel ivr
 
DOCX
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Rise With SAP partner in Mumbai.........
pts464036
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
DOCX
The Five Best AI Cover Tools in 2025.docx
aivoicelabofficial
 
PDF
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPTX
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
PPT
FALLSEM2025-26_ISWE304L_TH_VL2025260102786_2025-07-10_Reference-Material-II.ppt
AKSHAYA255427
 
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
PPTX
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
AIRLINE PRICE API | FLIGHT API COST |
philipnathen82
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Tier1 app
 
Benefits of DCCM for Genesys Contact Center
pointel ivr
 
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Rise With SAP partner in Mumbai.........
pts464036
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
The Five Best AI Cover Tools in 2025.docx
aivoicelabofficial
 
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
Exploring AI Agents in Process Industries
amoreira6
 
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
FALLSEM2025-26_ISWE304L_TH_VL2025260102786_2025-07-10_Reference-Material-II.ppt
AKSHAYA255427
 
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 

Data Types and Processing in ES6

  • 1. "When all you have is a hammer every problem looks like a nail" Abraham Maslow 1966
  • 3. Modularity Isolation Virtualisation Language Reform Tool / Lib Enabling Versioning Control Effects Draft 6th Edition Rev 24 (2014-04-27)
  • 6. Object • An Associative Array • maps string ➝ anything • prototypical inheritance
  • 7. var obj = new Object(); var obj = {}; // setting a value obj[ "key1" ] = "value1"; obj[ "key2" ] = window.document; obj[ "key3" ] = null // getting a value obj[ "key1" ]; // returns "value1" obj[ "toString" ]; // returns a function
  • 8. // iterating over keys for( key in obj ) { console.log( key, obj[ key ] ); } // maybe we should do this? for( key in obj ) { if( Object.prototype.hasOwnProperty.call( obj, key ) ) { console.log( key, obj[ key ] ); } }
  • 9. Is it for inheritance? Is it a data structure?
  • 10. Well… we have both, and it's not so great
  • 11. DON'T WORRY GUYS... DATA CONTROL IS HERE
  • 12. Array • You know them, you love them • maps number ➝ anything • plus magical length property
  • 13. var arr = new Array(); var arr = []; // constructing with the from method var imgs = Array.from( document.querySelectorAll( "IMG" ) ); var args = Array.from( arguments ); // with the spread operator var imgs = [ ...document.querySelectorAll( "IMG" ) ]; var args = [ ...arguments ];
  • 14. arr[0] = "value1"; arr[1] = new Anything(); arr.push( "value3" ); arr.slice; // etc arr[1]; // returns [object Anything] arr.pop(); // returns "value3" arr.indexOf( "value1" ); // returns 0 arr.length; // returns 2 for( let i = 0; i < arr.length; i++ ) { console.log( i, arr[i] ); } arr.forEach( fn ); arr.map( fn );
  • 15. Set • List of unique values • no duplicates allowed • does not map / associate with anything
  • 16. var set = new Set(); set.add( "key" ); set.add( 208 ); set.add( { name: "Schrödinger's Cat", alive: undefined } ); set.add( window.document ); set.add( NaN );
  • 17. var set = new Set(); var ann = { name: "Ann" }; var bob = { name: "Bob" }; set.add( ann ); set.add( bob ); set.has( ann ); // true set.add( ann ); set.size; // returns 2 set.delete( ann ); set.size; // returns 1
  • 18. Map • An associative array • maps anything ➝ anything
  • 19. var map = new Map(); map.set( "key1", "value1" ); map.set( null, "value2 ); map.set( window.document, function() { return true; } ); map.size; // returns 3 map.get( "key1" ); // returns "value1" map.get( null ); // returns "value2" map.delete( window.document ); map.clear();
  • 20. var ann = { name: "Ann" }; var bob = { name: "Bob" }; var age = new Map(); age.set( ann, 45 ); age.set( bob, 27 ); age.get( bob ); // returns 27
  • 21. WeakMap • Similar to Map • References to keys are weakly held • Maps objects ➝ anything • Does not have a determined size
  • 22. var handlers = new Map(); [ "ryanseddon", "paul_irish" ].forEach( function( name ) { var node = generateAvatarComponent( name ); handlers.set( node, showProfile ); parent.appendChild( node ); }); parent.remove(); // handlers contains 2 items // you have a memory leak
  • 23. var handlers = new WeakMap(); [ "ryanseddon", "paul_irish" ].forEach( function( name ) { var node = generateAvatarComponent( name ); handlers.set( node, showProfile ); parent.appendChild( node ); }); parent.remove(); // handlers is empty // no leaks!
  • 24. WeakSet • Weak version of Set • fairly limited use cases
  • 25. Iterators • An iterable lets you iterate over a list of values • An object that contains a next() method • returns an object containing { done, value } • Create Iterators from Array, Map and Set • Can NOT iterator over WeakMap and WeakSet
  • 26. var array = [ "a", "b", "c" ]; var iterator = array.entries(); iterator.next(); // returns { done: false, value: [ 0, "a" ] } iterator.next(); // returns { done: false, value: [ 1, "b" ] } iterator.next(); // returns { done: false, value: [ 2, "c" ] } iterator.next(); // returns { done: true, value: undefined } // with for of and destructuring for( var [ index, value ] of array.entries() ) { console.log( index, value ); } // compare for( let index = 0; index < array.length; index++ ) { console.log( index, array[ index ] ); }
  • 27. new Array( iterable ); new Map( iterable ); new Set( iterable ); array.entries(); // iterator returns [ index, value ] array.keys(); // iterator returns index array.values(); // iterator returns value map.entries(); // iterator returns [ key, value ] map.keys(); // iterator returns key map.values(); // iterator returns value set.entries(); // iterator returns [ key, key ] set.keys(); // iterator returns key set.values(); // iterator returns key
  • 28. Key Type Prototype conflict JSON Iterable Weak References size Object String Yes Yes No No No* Array Index No* Yes Yes No length Map Anything No No Yes No size Set Anything No No Yes No size WeakMap Object No No No Yes No WeakSet Object No No No Yes No
  • 29. Firefox IE11 Chrome1 Node2 Map / Set Yes Yes Yes Yes WeakMap / WeakSet Yes WeakMap only Yes Yes Iterables Non-conforming No Non-conforming No Destructuring Yes No No No Spread Yes No No No 1 requires enabling "experimental features" 2 requires running with the --harmony flag
  • 30. [email protected] name web site twitter / github email This is the end