💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
CMD规范是由国内的玉伯提出,与AMD规范的主要区别在于定义模块和依赖引入的部分。AMD需要在声明模块的时候指定所有的依赖,通过形参传递依赖到模块内容中: ~~~ define(['dep1','dep2'],function(dep1, dep2){ return function(){}; }); ~~~ 与AMD模块规范相比,CMD模块更接近于Node对CommonJS规范的定义: ~~~ define(factory); ~~~ 在依赖部分,CMD支持动态引入,示例如下: ~~~ define(function(require, exports, module){ // The module code goes here }); ~~~ require、exports和module通过形参传递给模块,在需要依赖模块时,随时调用require()引入即可。