Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
shobon-kun-no-module-hogehoge
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
mamoida
November 13, 2013
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
shobon-kun-no-module-hogehoge
mamoida
November 13, 2013
Other Decks in Programming
See All in Programming
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
ActionController meets Protocol Buffers
sorah
0
520
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
140
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
ジョジョの世界をXRで再現する
mofurune
0
160
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
Domain-Driven Transformation
hschwentner
2
2.3k
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
300
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
570
How STYLIGHT went responsive
nonsquared
100
6.3k
Balancing Empowerment & Direction
lara
6
1.3k
How to build a perfect <img>
jonoalderson
1
6.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Google's AI Overviews - The New Search
badams
0
1.6k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Facilitating Awesome Meetings
lara
57
7.2k
Visualization
eitanlees
153
17k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Transcript
(´ 3 `) Created by @mamoida
(´ 3 `) <
(´ 3 `) <
(function(win){ win.myModule = { some : function(){ console.log('some'); } };
})(window);
(´ 3 `) <
myModule.some(); // some
(´ 3 `) <
(´ 3 `) < node
$ node main.js ReferenceError: window is not defined
(´ 3 `) <
(´ 3 `) < node window
(´ 3 `) < window this
(function(root){ console.log(root); })(this);
Window {top: Window, window: Window, location: Location, external: Object, chrome:
Object⋯}
(´ 3 `) < window
$ node main.js {}
(´ 3 `) <
(´ 3 `) < this
(function(root){ console.log(this); })(this);
$ node main.js { ArrayBuffer: [Function: ArrayBuffer], Int8Array: { [Function:
Int8Array] BYTES_PER_ELEMENT: 1 }, Uint8Array: { [Function: Uint8Array] BYTES_PER_ELEMENT: 1 }, Uint8ClampedArray: { [Function: Uint8ClampedArray] BYTES_PER_ELEMENT: 1 }, Int16Array: { [Function: Int16Array] BYTES_PER_ELEMENT: 2 }, Uint16Array: { [Function: Uint16Array] BYTES_PER_ELEMENT: 2 }, Int32Array: { [Function: Int32Array] BYTES_PER_ELEMENT: 4 }, Uint32Array: { [Function: Uint32Array] BYTES_PER_ELEMENT: 4 }, Float32Array: { [Function: Float32Array] BYTES_PER_ELEMENT: 4 }, Float64Array: { [Function: Float64Array] BYTES_PER_ELEMENT: 8 }, ...
(´ 3 `) <
(´ 3 `) < node
var self = (function(root){ console.log(root === this); //false console.log(this.setTimeout); //[Function]
return this; })(this); console.log(self === this); // false console.log(this.setTimeout); // undefined console.log(setTimeout); // [Function]
(´ 3 `) < ...
(function(root){ console.log(typeof root.module); //undefined console.log(typeof module); //object console.log(typeof root.exports); //undefined
console.log(typeof exports); //object })(this); console.log(typeof this.module); //undefined console.log(typeof module); //object console.log(typeof root.exports); //undefined console.log(typeof exports); //object
module ( ) exports ( )
(´ 3 `) <
(´ 3 `) < exports node
(function(root){ if(typeof exports === 'object'){ module.exports = { some: function(){
console.log('some'); } }; }else{ root.myModule = { some: function(){ console.log('some'); } }; } })(this);
(´ 3 `) <
myModule.some(); // some
(´ 3 `) < node require
var myModule = require('./module.js'); myModule.some(); //some
(´ 3 `) < 2
(function(root){ var myModule = { some: function(){ console.log('some'); } };
if(typeof exports === 'object'){ module.exports = myModule; }else{ root.myModule = myModule; } })(this);
(´ 3 `) < AMD
(´ 3 `) < AMD ?
define.amd = {}; define(id?, dependencies? , factory)
define(['underscore'] , function(_){ return {}; });
(´ 3 `) < require.js
script(src="/js/lib/require.js")
(function(root){ console.log(typeof root.define); //function console.log(typeof root.define.amd); //object console.log(typeof root.require); //function
})(this);
(´ 3 `) <
(´ 3 `) <
(function(root){ var myModule = { some: function(){ console.log('some'); } };
if(typeof root.define === 'function' && define.amd){ define([],myModule); }else if(typeof exports === 'object'){ module.exports = myModule; }else{ root.myModule = myModule; } })(this);
(´ 3 `) < html
require.config({ baseUrl: '/js/', paths : {} }); require(['myModule'],function(myModule){ myModule.some(); });
(´ 3 `) <
(´ 3 `) <
(´ 3 `) < underscore
(function(root){ var myModule = { some: function(){ console.log('some'); } };
if(typeof root.define === 'function' && define.amd){ define(['underscore'],function(_){ return myModule; }); }else if(typeof exports === 'object'){ var underscore = require('underscore'); module.exports = function(underscore){ return myModule; }; }else{ root.myModule = function(_){ return myModule; }; } })(this);
(´ 3 `) <
(function(){ require.config({ baseUrl: '/js/', paths : { underscore : 'lib/underscore'
} }); require(['myModule'],function(myModule){ myModule.some(); }); })();
(´ 3 `) <
(function(root,factory){ if(typeof root.define === 'function' && define.amd){ define(['underscore'],factory); }else if(typeof
exports === 'object'){ module.exports = factory(require('underscore')); }else{ root.myModule = factory(_); } })(this,function(_){ var myModule = { some: function(){ console.log('some'); }, //メソッド追加 isArray : function(obj){ return _.isArray(obj); } }; return myModule; });
// browser with AMD (function(){ require.config({ baseUrl: '/js/', paths :
{ underscore : 'lib/underscore' } }); require(['myModule'],function(myModule){ myModule.some(); // some myModule.isArray({}); // false }); })();
// browser export script(src="/js/lib/underscore.js") script(src="/js/myModule.js") script. (function(){ myModule.some(); // some
myModule.isArray({}); // false })();
(´ 3 `) <
(´ 3 `) <
None
AMD · amdjs/amdjs-api Wiki umdjs/umd