肥胖症的危害>酥炸玉米粒
AMD,CMD,UMD三种模块规范写法格式⼀下三块均以 foo.js 为⽰例⽂件名,以 jQuery,underscore 为需求组件
ADM:异步模块规范, RequireJs 的⽀持格式
1// ⽂件名: foo.js
红烧鸡肉的做法
2 define(['jquery', 'underscore'], function ($, _) {
3// ⽅法
改装件
4function a(){}; // 私有⽅法,因为没有被返回(见下⾯)
5function b(){}; // 公共⽅法,因为被返回了
6function c(){}; // 公共⽅法,因为被返回了
7// 暴露公共⽅法
花灯谣
血小板减少吃什么好8return {
9 b: b,
10 c: c
11 }
12 });
CommonJs:node 的⽀持格式
1// ⽂件名: foo.js
2var $ = require('jquery');
3var _ = require('underscore');
4
5// methods
6function a(){}; // 私有⽅法,因为它没在ports中 (见下⾯)
7function b(){}; // 公共⽅法,因为它在ports中定义了
趣味运动会主题
8function c(){}; // 公共⽅法,因为它在ports中定义了
9
10// 暴露公共⽅法
ports = {
12 b: b,
13 c: c
14 };
UMD:通⽤模式,⽀持以上两种格式,切可以⽀持⽼式的 “全局变量” 规范
1 (function (root, factory) {
2if (typeof define === 'function' && define.amd) {
3// AMD
4 define(['jquery', 'underscore'], factory);
5 } el if (typeof exports === 'object') {
6// Node, CommonJS之类的
7 ports = factory(require('jquery'), require('underscore'));
8 } el {
9// 浏览器全局变量(root 即 window)
10 urnExports = factory(root.jQuery, root._);
11 }
12 }(this, function ($, _) {
13// ⽅法
14function a(){}; // 私有⽅法,因为它没被返回 (见下⾯)
猪的介绍
15function b(){}; // 公共⽅法,因为被返回了
16function c(){}; // 公共⽅法,因为被返回了
17
18// 暴露公共⽅法
19return {
20 b: b,
21 c: c
22 }
23 }));