Skip to content

与 RequireJS 的异同 #277

@lifesinger

Description

@lifesinger
Member

相同之处

RequireJS 和 Sea.js 都是模块加载器,倡导模块化开发理念,核心价值是让 JavaScript 的模块化开发变得简单自然。

不同之处

两者的主要区别如下:

  1. 定位有差异。RequireJS 想成为浏览器端的模块加载器,同时也想成为 Rhino / Node 等环境的模块加载器。Sea.js 则专注于 Web 浏览器端,同时通过 Node 扩展的方式可以很方便跑在 Node 环境中。
  2. 遵循的规范不同。RequireJS 遵循 AMD(异步模块定义)规范,Sea.js 遵循 CMD (通用模块定义)规范。规范的不同,导致了两者 API 不同。Sea.js 更贴近 CommonJS Modules/1.1 和 Node Modules 规范。
  3. 推广理念有差异。RequireJS 在尝试让第三方类库修改自身来支持 RequireJS,目前只有少数社区采纳。Sea.js 不强推,采用自主封装的方式来“海纳百川”,目前已有较成熟的封装策略。
  4. 对开发调试的支持有差异。Sea.js 非常关注代码的开发调试,有 nocache、debug 等用于调试的插件。RequireJS 无这方面的明显支持。
  5. 插件机制不同。RequireJS 采取的是在源码中预留接口的形式,插件类型比较单一。Sea.js 采取的是通用事件机制,插件类型更丰富。

还有不少差异,涉及具体使用方式和源码实现,欢迎有兴趣者研究并发表看法。

总之,如果说 RequireJS 是 Prototype 类库的话,则 Sea.js 致力于成为 jQuery 类库。

最重要的

最后,向 RequireJS 致敬!RequireJS 和 Sea.js 是好兄弟,一起努力推广模块化开发思想,这才是最重要的。

更新

参考

Activity

lifesinger

lifesinger commented on Jul 11, 2012

@lifesinger
MemberAuthor

有任何问题,欢迎留言交流。
注意:已解决的问题,会在整理后删除掉。

ufologist

ufologist commented on Jun 20, 2013

@ufologist

SeaJS与RequireJS最大的区别

执行模块的机制大不一样

SeaJS对模块的态度是懒执行, 而RequireJS对模块的态度是预执行

lifesinger

lifesinger commented on Jun 21, 2013

@lifesinger
MemberAuthor

@ufologist 嗯,推荐的文章真好,图文并茂。

wxg315699

wxg315699 commented on Feb 18, 2014

@wxg315699

推荐的图文并茂的文章有坑啊,现象确实是那么个现象,可是结论。。。实在不敢恭维

binggg

binggg commented on Jun 4, 2014

@binggg

as lazy as possible

zhishaofei3

zhishaofei3 commented on Jun 7, 2014

@zhishaofei3

nocache、debug 在哪找啊?

zhishaofei3

zhishaofei3 commented on Jun 7, 2014

@zhishaofei3

@afc163 谢谢

mycoin

mycoin commented on Jun 13, 2014

@mycoin

习惯使用 require.config配置, 并且只有两个命名空间的Loader,个人性格问题~

army8735

army8735 commented on Jun 13, 2014

@army8735
Member

@mycoin
两个命名空间是指?require和define?
seajs也是2个:seajs和define。

习惯问题的话其实简单:var require = seajs;delete seajs

mycoin

mycoin commented on Jun 13, 2014

@mycoin

@army8735 对的,因为使用标准的 require, define 可以在requireJS, esl, 等随意切换,这样也使得我的模块可以被所有类型的loader使用。

个人感觉这样才Common

13 remaining items

DarrenMan

DarrenMan commented on Mar 1, 2016

@DarrenMan

视自己需求而定吧

demox2026

demox2026 commented on Nov 13, 2016

@demox2026

能否结合ES6再来对比下呢

mygaochunming

mygaochunming commented on May 12, 2017

@mygaochunming

@lifesinger

从 RequireJS 到 Sea.js 系列:1~3打不开,是文章地址修改了吗?希望能够拜读一下

dhlolo

dhlolo commented on Sep 15, 2022

@dhlolo

用CMD同步的思路去处理异步问题:

  • lazy import使脚本模块复杂时效率方面得不到保证
  • 把setTimeout内部的代码认为需要符合同步顺序似乎也没啥好处
  • 倒是对于开发者节省了麻烦
summerhll

summerhll commented on Sep 15, 2022

@summerhll
gt333

gt333 commented on Sep 15, 2022

@gt333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lifesinger@ufologist@army8735@terranc@afc163

        Issue actions

          与 RequireJS 的异同 · Issue #277 · seajs/seajs