模块化开发规范:SeaJS

【前端面试知识题】- 模块化开发 就近依赖,需要时再进行加载,所以执行顺序和书写顺序一致;这一点与AMD不同,AMD是在使用模块之前将依赖模块全部加载完成,但由于网络等其他因素可能导致依赖模块下载的先后顺序不一致,这就造成执行顺序可能与书写顺序不一致。服务器端规范主要是 CommonJS, Node.js用的就是 CommonJS规范客户端规范主要有推崇依赖前置的AMD和推崇依赖就近的CMD。AMD规范的实现主要有 require.js。CMD规范的主要实现有 SeaJS。 阅读详情

和RequireJS类似,SeaJS也是一个适用于 Web 浏览器端的模块加载器,由前淘宝员工玉伯开发,后由阿里,腾讯等共同维护,目前被国外公司收购,在国内使用相对较少。可以在 SeaJS 详细学习。对SeaJS我们来做简单的了解,掌握基本使用方法。

项目目录

|--CMD
    |--js
        |--libs
            |--sea.js
        |--modules
            |--module1.js
            |--module2.js
            |--module3.js
            |--module4.js
        |--main.js
    |--index.html

定义模块

//module1.js
define(function (require, exports, module) {
    var msg = "module1";
    function foo(){
        return msg;
    }
    module.exports = {foo:foo};
})

//module2.js
define(function (require, exports, module) {
    var msg = "module2";
    function bar() {
        console.log(msg);
    };
    //暴露一个方法
    module.exports = bar;
})

//module3.js
define(function (require, exports, module) {
    var msg = "module3";
    function getMsg () {
        console.log(msg);
    }
    exports.fun = {getMsg:getMsg};
})

//module4.js
define(function (require, exports, module) {
    var msg = "module4";
    var module2 = require('./module2');
    //module2暴露的是一个方法,可以直接调用。
    module2();

    //异步引入module3
    require.async('./module3',function (module3) {
        module3.fun.getMsg();
    })

    function fun2() {
        console.log(msg);
    }
    exports.fun2 = fun2;
})

//main.js
//主模块不需要向外暴露接口,可以只给一个reuqire参数
define(function (require) {
    var module1 = require('./modules/module1');
    console.log(module1.foo());
    var module4 = require('./modules/module4');
    module4.fun2();
})

//index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>AMD-SEAJS</title>
</head>
<body>
    <!--引入sea.js-->
    <script src="./js/libs/sea.js"></script>
    <script>
        //使用seajs.use()方法加载主模块。
        seajs.use('./js/main.js');
    </script>
</body>
</html>

总结

SeaJS定义和暴露模块的方法结合了CommonJS和RequireJS中的方法,使用define()方式定义模块,使用module.exports或exports方法来暴露模块内容。会使用CommonJS和RequireJS学会使用SeaJS很简单。SeaJS中也可以配置选项,需要详细了解的建议访问SeaJS深入学习。

(04730)半导体器件之基本放大器工作原理(一) 放大器是构成各种电子线路的基本单元电路。所谓“放大”,就是将输入的微弱信号(微弱变化的电压或电流等)去控制直流电源提供的能量,并使输出按照输入的小信号变化规律而变化的过程。所以放大器的本质是能量转换器。本节重点学习基本放大电路的工作原理和基本分析方法及主要性能指标。 阅读详情

相关推荐

【Pico手势开发实战】基于SteamVR串流与MRTK3的跨平台交互方案

本文详细介绍了在Pico设备上,结合SteamVR串流与微软MRTK3框架,实现高效跨平台手势交互开发的完整方案。该方案通过在PC端运行Unity项目并串流至头显,利用MRTK3封装的手势识别与交互组件,大幅提升了开发调试效率与性能上限,并确保了未来向其他OpenXR设备的良好兼容性。

weixin_29001683的博客 217

seajs使用规范

作者:zccst 先温习一下define定义: define(function(require, exports, module){ }); [size=large][b]为什么要有约定和构建工具[/b][/size] [b]CMD模块的构建过程[/b] 1,提取操作,用来提取模块的标识 id 和依赖 dependencies。假设模块代码为: a.js define(...

zccst的专栏 192

IIR数字滤波器原理,设计方法及嵌入式应用

基于STM32的二阶直接II型巴特沃斯低通滤波器设计方法及应用

weixin_38342580的博客 1万+

sea.js

1:Sea.js简介 Sea.js,一个WEB模块加载框架,追求简单、自然的代码书写和组织方式。它遵循CMD规范,模块化JS代码。依赖自动加载, 配置的简洁清晰。 2:Sea.js的优缺点 优点: (1)提高可维护性 (2)模块化编程 (3)动态加载,前端性能优化 缺点: (1)学习的文档少而且混乱,会更改团队使用JS的编写习惯,必须使用模块化编程。 (2)不太适合团队目前的情

DreamsTom的博客 598

MCSDK5.4.8电机库双电阻采样适配:从扇区判断到固定采样的重构实践

本文详细解析了MCSDK5.4.8电机库中双电阻采样技术的重构实践,从扇区判断到固定采样的关键步骤。通过硬件配置优化、核心文件重构及电流读取函数改造,实现高效稳定的电机控制,特别适用于成本敏感型项目。文章还提供了占空比限制计算、参数调整及常见问题排查等实用技巧,助力工程师快速掌握两电阻采样方法。

weixin_42532938的博客 281

AutoDL上传数据详细步骤(自己用的步骤,可能没有其他大佬用的那么高级)

AutoDL上传数据详细步骤(自己用的步骤,可能没有其他大佬用的那么高级)

孟孟单单的博客 7万+

前端框架 seajs 使用总结

CMD 模块定义规范 seajs中,所有的javascript都遵循CMD模块定义规范。该规范明确定义了模块的定义格式和模块依赖的规则说明。define.cmd : 一个空对象,可以用来判断当前页面是否存在cmd模块加载器,调用方法如下: if(typeof define.cmd ==="undefined" || define.cmd){     //Seajs存在

爱编程 3925

软件需求规格说明书(SRS)深入解析

摘要: SRS(软件需求规格说明书)是定义系统功能、性能与接口的核心文档,为开发、测试、项目管理提供依据。标准结构包括引言、总体描述、功能/非功能需求、接口等模块。撰写需确保清晰、可验证、无歧义,避免模糊术语。示例展示学生注册模块的需求写法,强调性能与安全性要求。推荐使用Confluence、StarUML等工具辅助编写,交付时需包含主文档、原型图及需求跟踪矩阵。SRS应兼具技术性与管理性,作为沟通桥梁和验收标准。

moton2017的博客 2931

SeaJS 是什么?

seajs的价值原生javascript的一个弱项,就是不支持模块化,说白了就是没有其他语言的import,include等语句。所以开发者就只有2个选择:把所有的东西写到一起,或者通过全局变量来交互 这至少造成以下几个问题: 1、污染全局变量,容易发生命名空间冲突,难以维护 2、无法按需加载 由于javascript官方迟迟未能解决这些问题,所以就有民间的社区提出标准,希望能自行解决,弥补语言的...

大豆博文 2984

OSG 核心详解

OpenSceneGraph (OSG) 的核心架构、场景图管理以及几何体的绘制

qq_45859163的博客 729

CAN总线介绍及硬件设计

1. CAN是什么 CAN 是 Controller Area Network 的缩写(以下称为 CAN),是 ISO*1 国际标准化的串行通信协议。 在当前的汽车产业中,出于对安全性、舒适性、方便性、低公害、低成本的要求,各种各样的电子控制系统 被开发了出来。由于这些系统之间通信所用的数据类型及对可靠性的要求不尽相同,由多条总线构成的情况很 多,线束的数量也随之增加。为适应“减少线束的数量”、“......

sinat_15677011的博客 9992

再谈 JS中的模块规范(CommonJS,AMD,CMD)来自玉伯的seajs分析

随着互联网的飞速发展,前端开发越来越复杂。本文将从实际项目中遇到的问题出发,讲述模块化能解决哪些问题,以及如何使用 Sea.js 进行前端的模块化开发。恼人的命名冲突我们从一个简单的习惯出发。我做项目时,常常会将一些通用的、底层的功能抽象出来,独立成一个个函数,比如function each(arr) { // 实现代码 } function log(str) { // 实现代码 }并像

小北哥哥和北妈 2万+

《点云进阶》专栏文章目录

点云进阶》专栏文章目录

点云侠的博客 4905

AMD 和 CMD 的区别有哪些?

作者:玉伯 链接:https://www.zhihu.com/question/20351507/answer/14859415 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 AMD 规范在这里:https://github.com/amdjs/amdjs-api/wiki/AMD CMD 规范在这里:https://github.com/seajs/seajs...

fisher 255

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

JS模块化开发规范

JS模块化开发规范 commonJS规范 Nodejs模块系统遵循此规范,适用于服务端 1、 规范定义 CommonJS规范规定,一个文件就是一个模块,用module变量代表当前模块。 Node在其内部提供一个Module的构建函数。所有模块都是Module的实例; 一个单独的文件就是一个模块。每一个模块都是一个单独的作用域,也就是说,在该模块内部定义的变量,无法被其他模块读取,除非定义为global对象的属性; 2、 module.exports属性定义模块 module.exports属性表示当前模块对

starry__sty的博客 162

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

JS模块化开发:使用SeaJs高效构建页面

一、扯淡部分 很久很久以前,也就是刚开始接触前端的那会儿,脑袋里压根没有什么架构、重构、性能这些概念,天真地以为前端===好看的页面,甚至把js都划分到除了用来写一些美美的特效别无它用的阴暗角落里,就更别说会知道js还有面向对象,设计模式,MVC,MVVM,模块化,构建工具等等这些高大上的概念了。现在想想还真是Too young too naive。前两天某大神在群里分享他招聘前端的心得的时

小告白 960

模块化开发之CMD规范

欢迎访问我的博客https://qqqww.com/,祝码农同胞们早日走上人生巅峰,迎娶白富美~~~ 文章目录1 概念2 SeaJS2.1 定义模块2.2 加载模块3 参考文章 1 概念 CMD(Common Module Definition),通用模块定义,它解决的问题和AMD规范是一样的,只不过在模块定义方式和模块加载时机上不同,CMD也需要额外的引入第三方的库文件,SeaJS ...

王工头的博客 923

JavaScript模块化编程

最近项目上在做前端开发,用到的插件使用了RequireJS进行模块化,第一次接触,感觉挺实用的,大致研究了下,主要解决了目前JavaScript存在的两个问题:1.全局变量的命名冲突。2.JS文件依赖关系混乱。由于目前并没有官方认证的前端模块化标准,所以目前主流的就有AMD和CMD两种。

基因记忆 795

模块化开发规范

知识点1:AMD/CMD/CommonJs是JS模块化开发的标准,目前对应的实现是RequireJs/SeaJs/nodeJs. 知识点2:CommonJs主要针对服务端,AMD/CMD主要针对浏览器端,所以最容易混淆的是AMD/CMD。(顺便提一下,针对服务器端和针对浏览器端有什么本质的区别呢?服务器端一般采用同步加载文件,也就是说需要某个模块,服务器端便停下来,等待它加载再执行。...

weixin_30362801的博客 91

使用SeaJs高效构建页面

一、扯淡部分 很久很久以前,也就是刚开始接触前端的那会儿,脑袋里压根没有什么架构、重构、性能这些概念,天真地以为前端===好看的页面,甚至把js都划分到除了用来写一些美美的特效别无它用的阴暗角落里,就更别说会知道js还有面向对象,设计模式,MVC,MVVM,模块化,构建工具等等这些高大上的概念了。现在想想还真是Too young too naive。前两天某大神在群里分享他招聘前端的心得的时候

红星娃娃头 656

Js模块化开发--seajs和gruntJs

1.Seajs库 解决开发中的冲突依赖等问题,提供代码可维护性。 SeaJS 是由玉伯开发的一个遵循 CommonJS 规范的模块加载框架,可用来轻松愉悦地加载任意 JavaScript 模块和css模块样式。 SeaJS 就两个核心:模块定义和 模块的加载及依赖关系。 官方网站http://seajs.org 2.seajs如何使用? 主要有以下四个步骤: ...

weixin_30755393的博客 122

前端面试题之模块化开发

如今的前端工作中,模块化开发成为主流,无论是前端还是后端,由于模块化开发为我们带来巨大的收益,因此开发者都在使用它。前端培训模块化开发部分的面试题主要考察应试者对几种模块化开发规范的了解,应试者要明白它们之间的异同点,以及所适用的场合。 1、说说你对前端模块化开发的认识。 相关认识如下。 (1)异步模块定义(AMD)规范是 require. js推广的、对模块定义的规范。 (2)通用模块定义(CMD)规范是 SeaJS推广的、对模块定义的规范。 (3)AMD提前执行,CMD延迟执行 (4)AMD

m0_58371965的博客 287

前端模块化

模块化是指解决一个复杂问题时,自顶向下逐层把系统划分成若干模块的过程。对于整个系统来说,模块是可组合、分解和更换的单元.编程领域中的模块化,就是遵守固定的规则,把一个大文件拆成独立并互相依赖的多个小模块,是将不同功能的函数封装起来,并提供使用接口,他们彼此之间互不影响,想要什么功能,就加载什么模块,可以实现按需加载。简单来说,模块化就是把系统分割成独立的功能块,提高代码的复用性。

2302_80406801的博客 667

js模块化

AMD 规范在这里:https://github.com/amdjs/amdjs-api/wiki/AMDCMD 规范在这里:https://github.com/seajs/seajs/issues/242AMD 是 RequireJS 在推广过程中对模块定义的规范化产出。CMD 是 SeaJS 在推广过程中对模块定义的规范化产出。类似的还有 CommonJS Modules/2.0 规范,...

weixin_34242658的博客 69

【前端面试题】10—18道有关模块化开发的面试题(附答案)

如今的前端工作中,模块化开发成为主流,无论是前端还是后端,由于模块化开发为我们带来巨大的收益,因此开发者都在使用它。模块化开发部分的面试题主要考察应试者对几种模块化开发规范的了解,应试者要...

前端达人 1008
上一篇: 模块化开发规范:AMD(RequireJS)
下一篇: ES6模块化
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值