SlideShare a Scribd company logo
1 of 75
August 2015
There be dragons!
The Dragon of Syntax
The Node Dragon
Sonnet 130
The Browser Dragon
The Dragon of Syntax
Creating a module
export function doIt() {}
export var meaningOfLife = 42;
function doThat() {}
Using a module
import {doIt, meaningOfLife}
from 'a-module';
export function doIt() {}
export var meaningOfLife = 42
function doThat() {}
a-module.js
You Wish!
TIMTOWTDI
There Is More Than One Way To Do It
function doIt() {}
var aVar = 42;
function doThat() {...}
export {doIt,
aVar as meaningOfLife};
There Is More Than One Way To Do It
import * as lib from 'a-module';
lib.doIt();
lib.meaningOfLife;
AAAAARRRGGGGGHHH!!!
The dreaded default
export default 42;
import meaningOfLife
from 'a-module';
a-module.js
Confusion will be my epitaph
export default
function doIt() {}
export default var
meaningOfLife = 42;✕
✓
default is just another import
import orOther, {something}
from 'a-module';
import {something}, orOther
from 'a-module';
import {something, default as orOther}
from 'a-module';
TJTMWTTD!
There’s Just Too Many Ways To
Do Things!
Why Did This Happen?
So?
Do we abandon ship?
No!
Prefer default over specific exports
export default function
factory() {}
export default {
doIt() {}
meaningOfLife: 42
}
or...
Prefer const var bindings
export const meaningOfLife = 42;
The Dragon of Syntax
The Node Dragon
Sonnet 130
The Browser Dragon
The Node Dragon
How do we use ES6 modules in
Node?
Why would we do that?
Node has a really good module
system
Node module
exports.doIt = function() {}
exports.meaningOfLife = 42;
const {doIt, meaningOfLife} =
require('a-module');
a-module.js
Two words:
isomorphic code
So How?
Native ES6 modules:
ongoing work
Till then...
Babel!
require("babel/register");
Babel!
export function
doIt() {}
exports.doIt =
function() {}
import {doIt}
from 'a-module'
var {doIt} =
require('a-module')
default
export default 42; exports['default'] =
42
import mol
from 'a-module'
var {default: mol} =
require('a-module')
And this?
var aModule =
process.arch === 'win32' ?
require('a-module-win32') :
require('a-module')
//...
Huh? No dynamic loading of
modules?
There is!
var moduleName =
process.arch === 'win32' ?
'a-module-win32' : 'a-module’
System.import(‘a-module-win32’).then(
aModule => { /* ... */})
But it’s async!
the node people and ES6 people are currently
discussing how to resolve this
So?
Do we abandon ship?
No!
Do this
● Use import/export when you can
● Fall back to require if you must
The Dragon of Syntax
The Node Dragon
Sonnet 130
The Browser Dragon
The Browser Dragon
The fiercest dragon of them all
A whole talk unto itself
But maybe a glimpse?
This is illegal
<script>
import {doIt} from 'a-module';
// …
</script>
You have to do this
<script>
System.import('a-module').then(
({doIt}) =>
// ...
);
</script>
Or...
<script type=module>
import {doIt} from 'a-module';
// …
</script>
Or maybe...
<module>
import {doIt} from 'a-module';
// …
</module>
Who knows? The spec hasn’t been
updated in 10 months!
Extra! Extra! Read all about it!
Modules have their own scope
So forget about this
<module>
import {doIt} from 'a-module';
// …
</module>
<div onclick=doit>...</div>
Interoperability with AMD
● e.g. RequireJS?
● Maybe. There’s another spec, the Loader
spec, which is dealing with this
● Work in progress. Not yet close to ready.
● And has interoperability problems with Node
And how would this work
efficiently?
<module src= ></module>
So?
Do we abandon ship?
No!
The One-Two Punch
Punch #1
We’ve already seen it (Babel)
export function
doIt() {}
exports.doIt =
function() {}
import {doIt}
from 'a-module'
var {doIt} =
require('a-module')
Punch #2
Bundling CommonJS modules
bundle.js
Use...
● Grunt or Gulp or Brocolli or npm scripts
● Babel or Traceur or esnext
● webpack or browserify
But if you do all this, you get a
very sweet carrot
Isomorphic code between Node
and the Browser
The Dragon of Syntax
The Node Dragon
Sonnet 130
The Browser Dragon
Sonnet 130
My mistress’ eyes are nothing like the
sun;
Coral is far more red than her lips’
red;
If snow be white, why then her
breasts are dun;
If hairs be wires, black wires grow on
her head.
I have seen roses damasked, red
and white,
But no such roses see I in her
cheeks;
And in some perfumes is there more
delight
Than in the breath that from my
I grant I never saw a goddess go;
My mistress when she walks treads
on the ground.
And yet, by heaven, I think my
love as rare
As any she belied with false
compare.
So Go...
...and love ES6 modules like you love your
beloved:
it’s never perfect,
but it’s still wonderful,
and it gets better over time
Thank You
gil@tayar.org, @giltayar

More Related Content

What's hot

Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable ObjectsVictor Rentea
 
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & GeneratorsPython Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & GeneratorsP3 InfoTech Solutions Pvt. Ltd.
 
Java script good_bad_awful
Java script good_bad_awfulJava script good_bad_awful
Java script good_bad_awfulmoamen_mokhtar
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Victor Rentea
 
12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine12 Monkeys Inside JS Engine
12 Monkeys Inside JS EngineChengHui Weng
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricksOri Calvo
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
Groovy AST Demystified
Groovy AST DemystifiedGroovy AST Demystified
Groovy AST DemystifiedAndres Almiray
 
Say Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android DevelopmentSay Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android DevelopmentAdam Magaña
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devsAdit Lal
 
Definitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaDefinitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaVictor Rentea
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
Getting Started With Kotlin
Getting Started With KotlinGetting Started With Kotlin
Getting Started With KotlinGaurav sharma
 
A fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxA fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxPVS-Studio
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agentsRafael Winterhalter
 
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgeChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgePVS-Studio
 
Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1Andrey Karpov
 

What's hot (20)

Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable Objects
 
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & GeneratorsPython Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & Generators
 
Java script good_bad_awful
Java script good_bad_awfulJava script good_bad_awful
Java script good_bad_awful
 
Brython
BrythonBrython
Brython
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8
 
12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricks
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
Groovy AST Demystified
Groovy AST DemystifiedGroovy AST Demystified
Groovy AST Demystified
 
Say Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android DevelopmentSay Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android Development
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
Definitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaDefinitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in Java
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
Getting Started With Kotlin
Getting Started With KotlinGetting Started With Kotlin
Getting Started With Kotlin
 
A fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxA fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBox
 
Mock with Mockito
Mock with MockitoMock with Mockito
Mock with Mockito
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgeChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
 
Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1
 

Viewers also liked

SHODAN- Defcon 18-schearer-shodan
SHODAN- Defcon 18-schearer-shodanSHODAN- Defcon 18-schearer-shodan
SHODAN- Defcon 18-schearer-shodanIvan Flores
 
Networking Slides
Networking SlidesNetworking Slides
Networking Slidesiarthur
 
Inetsecurity.in Ethical Hacking presentation
Inetsecurity.in Ethical Hacking presentationInetsecurity.in Ethical Hacking presentation
Inetsecurity.in Ethical Hacking presentationJoshua Prince
 
Penetration Testing Basics
Penetration Testing BasicsPenetration Testing Basics
Penetration Testing BasicsRick Wanner
 
Ethical hacking & Information Security
Ethical hacking & Information SecurityEthical hacking & Information Security
Ethical hacking & Information SecurityAjay Dhamija
 
Computer networking devices
Computer networking devicesComputer networking devices
Computer networking devicesRajesh Sadhukha
 
BASIC CONCEPTS OF COMPUTER NETWORKS
BASIC CONCEPTS OF COMPUTER NETWORKS BASIC CONCEPTS OF COMPUTER NETWORKS
BASIC CONCEPTS OF COMPUTER NETWORKS Kak Yong
 

Viewers also liked (8)

SHODAN- Defcon 18-schearer-shodan
SHODAN- Defcon 18-schearer-shodanSHODAN- Defcon 18-schearer-shodan
SHODAN- Defcon 18-schearer-shodan
 
Networking Slides
Networking SlidesNetworking Slides
Networking Slides
 
Inetsecurity.in Ethical Hacking presentation
Inetsecurity.in Ethical Hacking presentationInetsecurity.in Ethical Hacking presentation
Inetsecurity.in Ethical Hacking presentation
 
Penetration Testing Basics
Penetration Testing BasicsPenetration Testing Basics
Penetration Testing Basics
 
Networking
NetworkingNetworking
Networking
 
Ethical hacking & Information Security
Ethical hacking & Information SecurityEthical hacking & Information Security
Ethical hacking & Information Security
 
Computer networking devices
Computer networking devicesComputer networking devices
Computer networking devices
 
BASIC CONCEPTS OF COMPUTER NETWORKS
BASIC CONCEPTS OF COMPUTER NETWORKS BASIC CONCEPTS OF COMPUTER NETWORKS
BASIC CONCEPTS OF COMPUTER NETWORKS
 

Similar to Navigating the wild seas of es6 modules

Unbundling the JavaScript module bundler - Codemotion Rome 2018
Unbundling the JavaScript module bundler - Codemotion Rome 2018Unbundling the JavaScript module bundler - Codemotion Rome 2018
Unbundling the JavaScript module bundler - Codemotion Rome 2018Luciano Mammino
 
Unbundling the JavaScript module bundler - Luciano Mammino - Codemotion Rome ...
Unbundling the JavaScript module bundler - Luciano Mammino - Codemotion Rome ...Unbundling the JavaScript module bundler - Luciano Mammino - Codemotion Rome ...
Unbundling the JavaScript module bundler - Luciano Mammino - Codemotion Rome ...Codemotion
 
MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodekinfusiondev
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS InternalEyal Vardi
 
Модули в С++ 20: хорошие, плохие и ужасные. Владислав Чехарев. CoreHard Sprin...
Модули в С++ 20: хорошие, плохие и ужасные. Владислав Чехарев. CoreHard Sprin...Модули в С++ 20: хорошие, плохие и ужасные. Владислав Чехарев. CoreHard Sprin...
Модули в С++ 20: хорошие, плохие и ужасные. Владислав Чехарев. CoreHard Sprin...corehard_by
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotTsai Tsung-Yi
 
Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Luciano Mammino
 
Unbundling the JavaScript module bundler - Road to Coderful
Unbundling the JavaScript module bundler - Road to CoderfulUnbundling the JavaScript module bundler - Road to Coderful
Unbundling the JavaScript module bundler - Road to CoderfulLuciano Mammino
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to GriffonJames Williams
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureIgalia
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS MeetupLINAGORA
 
2016 stop writing javascript frameworks by Joe Gregorio
2016 stop writing javascript frameworks by Joe Gregorio2016 stop writing javascript frameworks by Joe Gregorio
2016 stop writing javascript frameworks by Joe GregorioDavid Zapateria Besteiro
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018Luciano Mammino
 
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...Techsylvania
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)Soshi Nemoto
 

Similar to Navigating the wild seas of es6 modules (20)

Unbundling the JavaScript module bundler - Codemotion Rome 2018
Unbundling the JavaScript module bundler - Codemotion Rome 2018Unbundling the JavaScript module bundler - Codemotion Rome 2018
Unbundling the JavaScript module bundler - Codemotion Rome 2018
 
Unbundling the JavaScript module bundler - Luciano Mammino - Codemotion Rome ...
Unbundling the JavaScript module bundler - Luciano Mammino - Codemotion Rome ...Unbundling the JavaScript module bundler - Luciano Mammino - Codemotion Rome ...
Unbundling the JavaScript module bundler - Luciano Mammino - Codemotion Rome ...
 
MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodek
 
Griffon Presentation
Griffon PresentationGriffon Presentation
Griffon Presentation
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
Модули в С++ 20: хорошие, плохие и ужасные. Владислав Чехарев. CoreHard Sprin...
Модули в С++ 20: хорошие, плохие и ужасные. Владислав Чехарев. CoreHard Sprin...Модули в С++ 20: хорошие, плохие и ужасные. Владислав Чехарев. CoreHard Sprin...
Модули в С++ 20: хорошие, плохие и ужасные. Владислав Чехарев. CoreHard Sprin...
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobot
 
Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018
 
IOC + Javascript
IOC + JavascriptIOC + Javascript
IOC + Javascript
 
Unbundling the JavaScript module bundler - Road to Coderful
Unbundling the JavaScript module bundler - Road to CoderfulUnbundling the JavaScript module bundler - Road to Coderful
Unbundling the JavaScript module bundler - Road to Coderful
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and Future
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS Meetup
 
2016 stop writing javascript frameworks by Joe Gregorio
2016 stop writing javascript frameworks by Joe Gregorio2016 stop writing javascript frameworks by Joe Gregorio
2016 stop writing javascript frameworks by Joe Gregorio
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
 
Demystifying The Solid Works Api
Demystifying The Solid Works ApiDemystifying The Solid Works Api
Demystifying The Solid Works Api
 
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 

Navigating the wild seas of es6 modules

Editor's Notes

  1. This works well with the idea of modules as small pieces of code