SlideShare a Scribd company logo
Modules in JavaScript
    (and in EmbedJS)
Jens Arps
     @jensarps
     jensarps.de
github.com/jensarps




  uxebu.com
Q: Why modularize
    your code?
A: Code Organization
Code organization Top 5:


• Coder is forced to separate semantically different code.
• Small modules are easier to test.
• Small modules make errors easier to isolate.
• Self-contained modules make errors easier to fix.
• Other coders can easily join in on a project.
In an ideal world…
… there should also be a comfort bonus.
Dependency Resolution

Namespacing/Globals

      Loading
EmbedJS Section




              How we did modules in 0.1

            (Oh, yeah, and we did it wrong.)

                    (But we did it!)
EmbedJS Section



        External dependency declaration
        Script concatenation
        No loader
         Custom build tool
Modules in JavaScript
Scientifically correct description of module history:




     1. Community saw the need for modules
     2. NodeJS kicked in
     3. CommonJS evolved




             wiki.commonjs.org/wiki/Modules
Server => Client
Server => Client
Ideal-world scenario just dropped in!
EmbedJS Section




  Hell yeah! We want this!
Choosing the format:
AMD vs. CommonJS
https://www.google.com/search?q=AMD+vs+CommonJS
Specs:
http://wiki.commonjs.org/wiki/Modules

https://github.com/amdjs/amdjs-api/wiki
Also, check out @briancavalier‘s
             presentation on modules:


http://briancavalier.com/presentations/pgh-js-amd-10-2011/#0
You gotta choose yourself…
   (But I‘d go for AMD)
Or: UMD
 (Universal Module Definition)

(function (name, definition){
  if (typeof define === 'function'){ // AMD
    define(definition);
  } else if (typeof module !== 'undefined' && module.exports) { // Node.js
    module.exports = definition();
  } else { // Browser
    var theModule = definition(), global = this, old = global[name];
    theModule.noConflict = function () {
      global[name] = old;
      return theModule;
    };
    global[name] = theModule;
  }
})('myModule', function () {

  // return the module's API
  return {};

});




https://gist.github.com/1198466
https://gist.github.com/1262861
EmbedJS Section



                     AMD!

                  async is good
                  dojo goes for AMD
Choosing the tool
There‘s a couple of tools out there,
but only two can deal with CJS and AMD.



           curl.js
          RequireJS
Disclaimer: Personal Subjective Opinion




           Go for RequireJS
 James Burke is working on it like mad and it‘s getting
   more attention than any other loader out there.




           https://github.com/jrburke/requirejs/
Dynamic Loading
require(‘path/to/file’)

But: in a dynamic environment we don‘t
   know what file we need to load.
EmbedJS Section




   Features vs. Implementations
EmbedJS Section




   Features vs. Implementations

           You already happen to know this?
EmbedJS Section



           We don‘t want to require specific
           files, we want to require features.
EmbedJS Section



           We don‘t want to require specific
           files, we want to require features.



                  No custom tools, no moar!
Loader Plugins
https://github.com/amdjs/amdjs-api/wiki/Loader-Plugins
require(‘plugin!my/module’, …);

            text
            css
            cs
            has
            …
AMD Feature Plugin
AMD Feature Plugin
https://github.com/jensarps/AMD-feature
Finally, show some code already, dude!
Building
r.js
https://github.com/jrburke/r.js
Getting rid of require/define statements is still hard.
Synopsis
Go modules!
Go modules!

If you have multiple targets:

 Go features!
Thanks!

More Related Content

What's hot (16)

KEY
Zend Framework Modular Project Setup
chadrobertson75
 
PDF
Browserify
davidchubbs
 
PDF
JavaScript Patterns and Principles
Aaronius
 
PDF
Lightning Talk: Making JS better with Browserify
crgwbr
 
PDF
Workshop 16: EmberJS Parte I
Visual Engineering
 
PDF
AngularJS application architecture
Gabriele Falace
 
PDF
Grunt.js and Yeoman, Continous Integration
David Amend
 
PDF
General Assembly Workshop: Advanced JavaScript
Spike Brehm
 
PPTX
Workshop Intro: FrontEnd General Overview
Visual Engineering
 
PDF
Once upon a time, there were css, js and server-side rendering
Andrea Giannantonio
 
PDF
Develop plugin for Mozilla Firefox and structure a JS-based application
Afshin Mehrabani
 
PDF
JSConf US 2014: Building Isomorphic Apps
Spike Brehm
 
PDF
Building Isomorphic Apps (JSConf.Asia 2014)
Spike Brehm
 
PPTX
Kickstart sencha extjs
Shakti Shrestha
 
PDF
Angularjs interview questions and answers
Anil Singh
 
PDF
29 Essential AngularJS Interview Questions
Arc & Codementor
 
Zend Framework Modular Project Setup
chadrobertson75
 
Browserify
davidchubbs
 
JavaScript Patterns and Principles
Aaronius
 
Lightning Talk: Making JS better with Browserify
crgwbr
 
Workshop 16: EmberJS Parte I
Visual Engineering
 
AngularJS application architecture
Gabriele Falace
 
Grunt.js and Yeoman, Continous Integration
David Amend
 
General Assembly Workshop: Advanced JavaScript
Spike Brehm
 
Workshop Intro: FrontEnd General Overview
Visual Engineering
 
Once upon a time, there were css, js and server-side rendering
Andrea Giannantonio
 
Develop plugin for Mozilla Firefox and structure a JS-based application
Afshin Mehrabani
 
JSConf US 2014: Building Isomorphic Apps
Spike Brehm
 
Building Isomorphic Apps (JSConf.Asia 2014)
Spike Brehm
 
Kickstart sencha extjs
Shakti Shrestha
 
Angularjs interview questions and answers
Anil Singh
 
29 Essential AngularJS Interview Questions
Arc & Codementor
 

Viewers also liked (6)

PPT
LMS Parent Night May 25 2011
azuck
 
PPT
Welcome back 8 31
azuck
 
PDF
LMS Parent Information Meeting 5 25
azuck
 
PPT
Lml intro new teachers
azuck
 
PPT
Lesson plan presentation aug 2012
azuck
 
PPTX
September 1 technology presentation
azuck
 
LMS Parent Night May 25 2011
azuck
 
Welcome back 8 31
azuck
 
LMS Parent Information Meeting 5 25
azuck
 
Lml intro new teachers
azuck
 
Lesson plan presentation aug 2012
azuck
 
September 1 technology presentation
azuck
 
Ad

Similar to Modules and EmbedJS (20)

PDF
Modular JavaScript in an OSGi World - S Mak
mfrancis
 
PDF
IOC + Javascript
Brian Cavalier
 
PDF
JavaScript Modules Done Right
Mariusz Nowak
 
PPTX
uRequire@greecejs: An introduction to http://uRequire.org
Agelos Pikoulas
 
PDF
Webpack: your final module bundler
Andrea Giannantonio
 
PDF
Advanced Node.JS Meetup
LINAGORA
 
PPSX
RequireJS
Tim Doherty
 
PDF
Workshop 2: JavaScript Design Patterns
Visual Engineering
 
PPTX
JavaScript Module Loaders
zeroproductionincidents
 
PDF
Seven Versions of One Web Application
Yakov Fain
 
PPT
JavaScript Modules in Practice
Maghdebura
 
PDF
Module, AMD, RequireJS
偉格 高
 
PDF
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
PDF
Handlebars and Require.js
Ivano Malavolta
 
PDF
Modular JavaScript
NLJUG
 
PPTX
OpenDaylight Developer Experience 2.0
Michael Vorburger
 
PDF
From Idea to App (or “How we roll at Small Town Heroes”)
Bramus Van Damme
 
PPTX
node.js.pptx
rani marri
 
PDF
Handlebars & Require JS
Ivano Malavolta
 
PDF
Modern UI Development With Node.js
Ryan Anklam
 
Modular JavaScript in an OSGi World - S Mak
mfrancis
 
IOC + Javascript
Brian Cavalier
 
JavaScript Modules Done Right
Mariusz Nowak
 
uRequire@greecejs: An introduction to http://uRequire.org
Agelos Pikoulas
 
Webpack: your final module bundler
Andrea Giannantonio
 
Advanced Node.JS Meetup
LINAGORA
 
RequireJS
Tim Doherty
 
Workshop 2: JavaScript Design Patterns
Visual Engineering
 
JavaScript Module Loaders
zeroproductionincidents
 
Seven Versions of One Web Application
Yakov Fain
 
JavaScript Modules in Practice
Maghdebura
 
Module, AMD, RequireJS
偉格 高
 
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
Handlebars and Require.js
Ivano Malavolta
 
Modular JavaScript
NLJUG
 
OpenDaylight Developer Experience 2.0
Michael Vorburger
 
From Idea to App (or “How we roll at Small Town Heroes”)
Bramus Van Damme
 
node.js.pptx
rani marri
 
Handlebars & Require JS
Ivano Malavolta
 
Modern UI Development With Node.js
Ryan Anklam
 
Ad

Recently uploaded (20)

PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 

Modules and EmbedJS

Editor's Notes