Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
前端组件模块化思考与实践
Search
keelii
March 08, 2013
Programming
4
1.1k
前端组件模块化思考与实践
前端组件模块化思考与实践
keelii
March 08, 2013
Tweet
Share
More Decks by keelii
See All by keelii
Best workflow with grunt
keelii
0
1k
前端,改变 Front-end makes change
keelii
5
1k
前端开发工具
keelii
3
1.1k
Other Decks in Programming
See All in Programming
How Android Uses Data Structures Behind The Scenes
l2hyunwoo
0
480
OSS開発者という働き方
andpad
5
1.7k
詳解!defer panic recover のしくみ / Understanding defer, panic, and recover
convto
0
250
AWS発のAIエディタKiroを使ってみた
iriikeita
1
190
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
4
1.5k
Testing Trophyは叫ばない
toms74209200
0
890
楽して成果を出すためのセルフリソース管理
clipnote
0
190
ぬるぬる動かせ! Riveでアニメーション実装🐾
kno3a87
1
230
テストコードはもう書かない:JetBrains AI Assistantに委ねる非同期処理のテスト自動設計・生成
makun
0
560
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
110
「手軽で便利」に潜む罠。 Popover API を WCAG 2.2の視点で安全に使うには
taitotnk
0
870
複雑なフォームに立ち向かう Next.js の技術選定
macchiitaka
2
240
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Automating Front-end Workflow
addyosmani
1370
200k
It's Worth the Effort
3n
187
28k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
BBQ
matthewcrist
89
9.8k
Facilitating Awesome Meetings
lara
55
6.5k
Fireside Chat
paigeccino
39
3.6k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
How GitHub (no longer) Works
holman
315
140k
Optimizing for Happiness
mojombo
379
70k
RailsConf 2023
tenderlove
30
1.2k
Optimising Largest Contentful Paint
csswizardry
37
3.4k
Transcript
前端组件模块化思考与实践 ——requirejs VS seajs 13年2月22⽇日星期五
思考 ✦为什么需要模块化 ✦模块化的优缺点 实践 ✦模块定义规范 ✦AMD VS CMD ✦requirejs VS
seajs 13年2月22⽇日星期五
思考 ✦为什么需要模块化 ✦模块化的优缺点 实践 ✦模块定义规范 ✦AMD VS CMD ✦requirejs VS
seajs 13年2月22⽇日星期五
13年2月22⽇日星期五
原因 ⽷为什么需要模块化⽺ 13年2月22⽇日星期五
原因 ⽷为什么需要模块化⽺ ✦前端开发流程规范化 13年2月22⽇日星期五
原因 ⽷为什么需要模块化⽺ ✦前端开发流程规范化 ✦业务与需求更复杂 13年2月22⽇日星期五
原因 ⽷为什么需要模块化⽺ ✦前端开发流程规范化 ✦业务与需求更复杂 ✦代码复⽤用、架构升级 13年2月22⽇日星期五
思考 ✦为什么需要模块化 ✦模块化的优缺点 实践 ✦模块定义规范 ✦AMD VS CMD ✦requirejs VS
seajs 13年2月22⽇日星期五
优缺点 ⽷模块化的优缺点⽺ 13年2月22⽇日星期五
优缺点 ⽷模块化的优缺点⽺ ✓代码复⽤用强、提⾼高开发效率 ✓有利于开发规范与⽂文档系统 ✓模块依赖关系系统解决使开发更专注 13年2月22⽇日星期五
优缺点 ⽷模块化的优缺点⽺ ✓代码复⽤用强、提⾼高开发效率 ✓有利于开发规范与⽂文档系统 ✓模块依赖关系系统解决使开发更专注 ✦模块粒度过⾼高不利于管理 ✦额外的学习成本 13年2月22⽇日星期五
13年2月22⽇日星期五
思考 ✦为什么需要模块化 ✦模块化的优缺点 实践 ✦模块定义规范 ✦AMD VS CMD ✦requirejs VS
seajs 13年2月22⽇日星期五
CommonJS模块规范 13年2月22⽇日星期五
CommonJS模块规范 CommonJS 是⼀一个有志于构建 JavaScript ⽣生态圈的组 织。它有⼀一个 邮件列表,很多开发者参与其中。 整个社 区致⼒力于提⾼高 JavaScript
程序的可移植性和可交换性, ⽆无论是在服务端还是浏览器端。——lifesinger 13年2月22⽇日星期五
CommonJS的两个字规范 Module/AMD Asynchronous Module Definition Module/Wrappings Common Module Definition CommonJS
13年2月22⽇日星期五
CommonJS的两个字规范 Module/AMD Asynchronous Module Definition Module/Wrappings Common Module Definition CommonJS
13年2月22⽇日星期五
CommonJS的两个字规范 Module/AMD Asynchronous Module Definition Module/Wrappings Common Module Definition CommonJS
13年2月22⽇日星期五
CommonJS的两个字规范 Module/AMD Asynchronous Module Definition Module/Wrappings Common Module Definition CommonJS
13年2月22⽇日星期五
CommonJS的两个字规范 Module/AMD Asynchronous Module Definition Module/Wrappings Common Module Definition requirejs
CommonJS 13年2月22⽇日星期五
CommonJS的两个字规范 Module/AMD Asynchronous Module Definition Module/Wrappings Common Module Definition requirejs
CommonJS 13年2月22⽇日星期五
CommonJS的两个字规范 Module/AMD Asynchronous Module Definition Module/Wrappings Common Module Definition requirejs
seajs CommonJS 13年2月22⽇日星期五
AMD模块规范 define require 13年2月22⽇日星期五
定义⼀一个模块 define(id?, deps?, factory) 13年2月22⽇日星期五
定义⼀一个模块 define(id?, deps?, factory) string 模块标识 13年2月22⽇日星期五
定义⼀一个模块 define(id?, deps?, factory) string 模块标识 string/array 依赖数组 13年2月22⽇日星期五
定义⼀一个模块 define(id?, deps?, factory) string 模块标识 string/array 依赖数组 function ⼯工⼚厂函数
13年2月22⽇日星期五
加载⼀一个模块 require([‘modules’], callback) 13年2月22⽇日星期五
加载⼀一个模块 require([‘modules’], callback) string/array 加载数组 13年2月22⽇日星期五
加载⼀一个模块 require([‘modules’], callback) string/array 加载数组 function 加载成功回调函数 13年2月22⽇日星期五
define⽤用例 define(‘fp’, [‘jquery’, ‘trimpath’], function() { var footPrint = function()
{ // code here } // 模块对外开放的变量、⽅方法、对象 return footPrint; }); 13年2月22⽇日星期五
require⽤用例 require([‘jquery’, ‘fp’], function(jquery, footprint) { // dom加载完成后初始化脚印模块 $(function() {
var fp = new footPrint(); }); }); 13年2月22⽇日星期五
SeaJS ? 13年2月22⽇日星期五
SeaJS ? coming soon... 13年2月22⽇日星期五
RequireJS 对⽐比 SeaJS requirejs(15kb) seajs (7kb) AMD应⽤用⼲⼴广泛,对AMD⽀支持 良好 另辟蹊径选择 Wrappings⾃自⽴立
⻔门户,语法优雅、更适合浏览 器端 脚本加载器+模块加载器 纯粹的模块加载器 AMD天然⽀支持JSONP模块 模块内部按需异步加载 13年2月22⽇日星期五
引⽤用: https://github.com/amdjs/amdjs-api/wiki/AMD https://github.com/seajs/seajs https://github.com/jrburke/requirejs 13年2月22⽇日星期五
END 13年2月22⽇日星期五