SlideShare a Scribd company logo
CommonJS Modules
var PI = 3.14159265359;
function circumference(radius) {
return 2 * PI * radius;
}
function area(radius) {
return PI * radius * radius;
}
module.exports = {
PI: PI,
circumference: circumference,
area: area
};
var geometry = require('./geometry');
var circumference = geometry.circumference(10);
var area = geometry.area(10);
geometry.js
app.js
Runtime provides
module reference
Functions are
namespaced to
module
AMD Modules
geometry.js
define('geometry', [], function () {
var PI = 3.14159265359;
function circumference(radius) {
return 2 * PI * radius;
}
function area(radius) {
return PI * radius * radius;
}
return {
PI: PI,
circumference: circumference,
area: area
};
});
app.js
define(['geometry'], function (geometry) {
var circumference = geometry.circumference(10);
var area = geometry.area(10);
});
Dependencies
specified in array
passed to define
Module returned
as object
ES2015 Modules: Named Exports
export const PI = 3.14159265359;
export function circumference(radius) {
return 2 * PI * radius;
}
export function area(radius) {
return PI * radius * radius;
}
geometry.js
import { circumference, area } from './geometry';
const theCircumference = circumference(10);
const theArea = area(10);
app.js
New export
keyword
New import
keyword
Dependencies
imported by name
ES2015 Modules: Named Exports
const PI = 3.14159265359;
function circumference(radius) {
return 2 * PI * radius;
}
function area(radius) {
return PI * radius * radius;
}
export { PI, circumference, area };
geometry.js
import { circumference, area } from './geometry';
const theCircumference = circumference(10);
const theArea = area(10);
app.js
Exports at end of
file
Same imports
ES2015 Modules: Namespaced Imports
export const PI = 3.14159265359;
export function circumference(radius) {
return 2 * PI * radius;
}
export function area(radius) {
return PI * radius * radius;
}
geometry.js
import * as geometry from './geometry';
Const circumference = geometry.circumference(10);
const area = geometry.area(10);
app.js
Same as before
Imported
dependencies
namespaced
ES2015 Modules: Default Export
import React from 'react';
export default class LoginPage extends React.Component {
render() {
return <form> ... </form>;
}
}
LoginPage.jsx
import ReactDOM from 'react-dom';
import LoginPage from './LoginPage’;
ReactDOM.render(<LoginPage />,
document.getElementById('app');
App.jsx
Default export
Alias for default
export
import ReactDOM from 'react-dom';
import AppLoginPage from './LoginPage’;
ReactDOM.render(<LoginPage />,
document.getElementById('app');
App.jsx
Alias does not
have to match
exported item
name
ES2015 Modules: Mixed Exports
import React from 'react';
import { connect } from 'react-redux';
export class TodoList extends React.Component {
render() {
return <div> ... </div>;
}
}
export default connect()(TodoList);
TodoList.jsx
import ReactDOM from 'react-dom';
import ConnectedTodoList from './TodoList';
ReactDOM.render(<ConnectedTodoList />,
document.getElementById('app');
App.jsx
import TestUtils from 'react-addons-test-utils';
import { TodoList } from '../components/TodoList';
const todoList = TestUtils.renderIntoDocument(<TodoList />);
TodoListTest.jsx
Default export
and named export
Using default
export
Using named
export
ES2015 Modules: Mixed Imports
const ACTIONS = {
LOG_IN: 'LOG_IN',
LOG_OUT: 'LOG_OUT'
};
export default ACTIONS;
export function login(username, password) { ... }
export function logout()
actions.js
import actions, { login, logout } from '../actions/actions';
console.log(`Performing action ${actions.LOG_OUT}`);
logout();
app.js
Importing default
export and named
exports
Using default
export and named
exports
Referencing
default export
Referencing
named export
ES2015 Modules: Aliases
function myReallyLongFunctionName() {
...
}
export { myReallyLongFunctionName as foo };
module.js
import { foo as someOtherName } from './module';
someOtherName();
app.js
foo is aliased as
someOtherName
Long function
name is aliased as
foo

More Related Content

What's hot

More Than po: Debugging in LLDB @ CocoaConf SJ 2015
More Than po: Debugging in LLDB @ CocoaConf SJ 2015More Than po: Debugging in LLDB @ CocoaConf SJ 2015
More Than po: Debugging in LLDB @ CocoaConf SJ 2015
Michele Titolo
 
Scientific calcultor-Java
Scientific calcultor-JavaScientific calcultor-Java
Scientific calcultor-Java
Shaibal Ahmed
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
Mouna Guru
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
Vincent Pradeilles
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
Kris Kowal
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
AhalyaR
 
Advanced functional programing in Swift
Advanced functional programing in SwiftAdvanced functional programing in Swift
Advanced functional programing in Swift
Vincent Pradeilles
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
vandna123
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
Adam Crabtree
 
Java final project of scientific calcultor
Java final project of scientific calcultorJava final project of scientific calcultor
Java final project of scientific calcultor
Md. Eunus Ali Rupom
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
Ankit Gupta
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Node js
Node jsNode js
Node js
LearningTech
 
Java script
Java scriptJava script
Java script
Dhananjay Kumar
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
Thesis Scientist Private Limited
 
Check the output of the following code then recode it to eliminate fu
 Check the output of the following code then recode it to eliminate fu Check the output of the following code then recode it to eliminate fu
Check the output of the following code then recode it to eliminate fu
licservernoida
 
Svitla talks 2021_03_25
Svitla talks 2021_03_25Svitla talks 2021_03_25
Svitla talks 2021_03_25
Ruslan Shevchenko
 
Building l10n Payroll Structures from the Ground up
Building l10n Payroll Structures from the Ground upBuilding l10n Payroll Structures from the Ground up
Building l10n Payroll Structures from the Ground up
Odoo
 
operator overloading
operator overloadingoperator overloading
operator overloading
Nishant Joshi
 
Functional programming principles
Functional programming principlesFunctional programming principles
Functional programming principles
Andrew Denisov
 

What's hot (20)

More Than po: Debugging in LLDB @ CocoaConf SJ 2015
More Than po: Debugging in LLDB @ CocoaConf SJ 2015More Than po: Debugging in LLDB @ CocoaConf SJ 2015
More Than po: Debugging in LLDB @ CocoaConf SJ 2015
 
Scientific calcultor-Java
Scientific calcultor-JavaScientific calcultor-Java
Scientific calcultor-Java
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
Advanced functional programing in Swift
Advanced functional programing in SwiftAdvanced functional programing in Swift
Advanced functional programing in Swift
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
 
Java final project of scientific calcultor
Java final project of scientific calcultorJava final project of scientific calcultor
Java final project of scientific calcultor
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
functions of C++
functions of C++functions of C++
functions of C++
 
Node js
Node jsNode js
Node js
 
Java script
Java scriptJava script
Java script
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
Check the output of the following code then recode it to eliminate fu
 Check the output of the following code then recode it to eliminate fu Check the output of the following code then recode it to eliminate fu
Check the output of the following code then recode it to eliminate fu
 
Svitla talks 2021_03_25
Svitla talks 2021_03_25Svitla talks 2021_03_25
Svitla talks 2021_03_25
 
Building l10n Payroll Structures from the Ground up
Building l10n Payroll Structures from the Ground upBuilding l10n Payroll Structures from the Ground up
Building l10n Payroll Structures from the Ground up
 
operator overloading
operator overloadingoperator overloading
operator overloading
 
Functional programming principles
Functional programming principlesFunctional programming principles
Functional programming principles
 

Similar to ES2015 Modules

React lecture
React lectureReact lecture
React lecture
Christoffer Noring
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
Pierre-Yves Ricau
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
Visual Engineering
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
Eyal Vardi
 
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorDaggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processor
Bartosz Kosarzycki
 
React for Re-use: Creating UI Components with Confluence Connect
React for Re-use: Creating UI Components with Confluence ConnectReact for Re-use: Creating UI Components with Confluence Connect
React for Re-use: Creating UI Components with Confluence Connect
Atlassian
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
Alfonso Fernández
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Codemotion
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
Astrails
 
Node.js server-side rendering
Node.js server-side renderingNode.js server-side rendering
Node.js server-side rendering
The Software House
 
React native by example by Vadim Ruban
React native by example by Vadim RubanReact native by example by Vadim Ruban
React native by example by Vadim Ruban
Lohika_Odessa_TechTalks
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
[T]echdencias
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
GeeksLab Odessa
 
Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render Props
Nitish Phanse
 
Richard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptuRichard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptu
Develcz
 
React redux
React reduxReact redux
React redux
Michel Perez
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
Kamil Augustynowicz
 
Using react with meteor
Using react with meteorUsing react with meteor
Using react with meteor
NodeXperts
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
Rob Tweed
 
Already given code from 4 files- 1-app-ctrl-js code- -- include expres.pdf
Already given code from 4 files- 1-app-ctrl-js code- -- include expres.pdfAlready given code from 4 files- 1-app-ctrl-js code- -- include expres.pdf
Already given code from 4 files- 1-app-ctrl-js code- -- include expres.pdf
as1mobiles
 

Similar to ES2015 Modules (20)

React lecture
React lectureReact lecture
React lecture
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorDaggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processor
 
React for Re-use: Creating UI Components with Confluence Connect
React for Re-use: Creating UI Components with Confluence ConnectReact for Re-use: Creating UI Components with Confluence Connect
React for Re-use: Creating UI Components with Confluence Connect
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
 
Node.js server-side rendering
Node.js server-side renderingNode.js server-side rendering
Node.js server-side rendering
 
React native by example by Vadim Ruban
React native by example by Vadim RubanReact native by example by Vadim Ruban
React native by example by Vadim Ruban
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
 
Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render Props
 
Richard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptuRichard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptu
 
React redux
React reduxReact redux
React redux
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
 
Using react with meteor
Using react with meteorUsing react with meteor
Using react with meteor
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
 
Already given code from 4 files- 1-app-ctrl-js code- -- include expres.pdf
Already given code from 4 files- 1-app-ctrl-js code- -- include expres.pdfAlready given code from 4 files- 1-app-ctrl-js code- -- include expres.pdf
Already given code from 4 files- 1-app-ctrl-js code- -- include expres.pdf
 

Recently uploaded

Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
ssuserad3af4
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
Ayan Halder
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
Drona Infotech
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 

Recently uploaded (20)

Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 

ES2015 Modules

  • 1.
  • 2. CommonJS Modules var PI = 3.14159265359; function circumference(radius) { return 2 * PI * radius; } function area(radius) { return PI * radius * radius; } module.exports = { PI: PI, circumference: circumference, area: area }; var geometry = require('./geometry'); var circumference = geometry.circumference(10); var area = geometry.area(10); geometry.js app.js Runtime provides module reference Functions are namespaced to module
  • 3. AMD Modules geometry.js define('geometry', [], function () { var PI = 3.14159265359; function circumference(radius) { return 2 * PI * radius; } function area(radius) { return PI * radius * radius; } return { PI: PI, circumference: circumference, area: area }; }); app.js define(['geometry'], function (geometry) { var circumference = geometry.circumference(10); var area = geometry.area(10); }); Dependencies specified in array passed to define Module returned as object
  • 4. ES2015 Modules: Named Exports export const PI = 3.14159265359; export function circumference(radius) { return 2 * PI * radius; } export function area(radius) { return PI * radius * radius; } geometry.js import { circumference, area } from './geometry'; const theCircumference = circumference(10); const theArea = area(10); app.js New export keyword New import keyword Dependencies imported by name
  • 5. ES2015 Modules: Named Exports const PI = 3.14159265359; function circumference(radius) { return 2 * PI * radius; } function area(radius) { return PI * radius * radius; } export { PI, circumference, area }; geometry.js import { circumference, area } from './geometry'; const theCircumference = circumference(10); const theArea = area(10); app.js Exports at end of file Same imports
  • 6. ES2015 Modules: Namespaced Imports export const PI = 3.14159265359; export function circumference(radius) { return 2 * PI * radius; } export function area(radius) { return PI * radius * radius; } geometry.js import * as geometry from './geometry'; Const circumference = geometry.circumference(10); const area = geometry.area(10); app.js Same as before Imported dependencies namespaced
  • 7. ES2015 Modules: Default Export import React from 'react'; export default class LoginPage extends React.Component { render() { return <form> ... </form>; } } LoginPage.jsx import ReactDOM from 'react-dom'; import LoginPage from './LoginPage’; ReactDOM.render(<LoginPage />, document.getElementById('app'); App.jsx Default export Alias for default export import ReactDOM from 'react-dom'; import AppLoginPage from './LoginPage’; ReactDOM.render(<LoginPage />, document.getElementById('app'); App.jsx Alias does not have to match exported item name
  • 8. ES2015 Modules: Mixed Exports import React from 'react'; import { connect } from 'react-redux'; export class TodoList extends React.Component { render() { return <div> ... </div>; } } export default connect()(TodoList); TodoList.jsx import ReactDOM from 'react-dom'; import ConnectedTodoList from './TodoList'; ReactDOM.render(<ConnectedTodoList />, document.getElementById('app'); App.jsx import TestUtils from 'react-addons-test-utils'; import { TodoList } from '../components/TodoList'; const todoList = TestUtils.renderIntoDocument(<TodoList />); TodoListTest.jsx Default export and named export Using default export Using named export
  • 9. ES2015 Modules: Mixed Imports const ACTIONS = { LOG_IN: 'LOG_IN', LOG_OUT: 'LOG_OUT' }; export default ACTIONS; export function login(username, password) { ... } export function logout() actions.js import actions, { login, logout } from '../actions/actions'; console.log(`Performing action ${actions.LOG_OUT}`); logout(); app.js Importing default export and named exports Using default export and named exports Referencing default export Referencing named export
  • 10. ES2015 Modules: Aliases function myReallyLongFunctionName() { ... } export { myReallyLongFunctionName as foo }; module.js import { foo as someOtherName } from './module'; someOtherName(); app.js foo is aliased as someOtherName Long function name is aliased as foo

Editor's Notes

  1. asdf
  2. asdf