✳flâneur — a map of the web's best reading
CommonJS规范 -- JavaScript 标准参考教程(alpha)
javascript.ruanyifeng.com · 1,521 words · saved by 1 readers
CommonJS规范规定,每个模块内部,module变量代表当前模块。这个变量是一个对象,它的exports属性(即module.exports)是对外的接口。加载某个模块,其实是加载该模块的module.exports属性。
CommonJS规范 来自 《JavaScript 标准参考教程(alpha)》 ,by 阮一峰 目录 重要说明:本教程已经搬迁,此处不再维护,请访问新网址: wangdoc.com/javascript 。 概述 Node 应用由模块组成,采用 CommonJS 模块规范。 每个文件就是一个模块,有自己的作用域。在一个文件里面定义的变量、函数、类,都是私有的,对其他文件不可见。 // example.js var x = 5 ; var addX = function ( value ) { return value + x ; }; 上面代码中,变量 x 和函数 addX ,是当前文件 example.js 私有的,其他文件不可见。 如果想在多个文件分享变量,必须定义为 global 对象的属性。 global . warning = true ; 上面代码的 warning 变量,可以被所有文件读取。当然,这样写法是不推荐的。 CommonJS规范规定,每个模块内部, module 变量代表当前模块。这个变量是一个对象,它的 exports 属性(即 module.exports )是对外的接口。加载某个模块,其实是加载该模块的 module.exports 属性。 var x = 5 ; var addX = function ( value ) { return valu
Explore this link on the map →saved by
related reading
- ES modules: A cartoon deep-dive - Mozilla Hacks - the Web developer bloghacks.mozilla.org
- Modules :: Eloquent JavaScripteloquentjavascript.net
- CommonJS effort sets JavaScript on path for world domination - Ars Technicaarstechnica.com
- Demystifying Code Bundling with JavaScript Modules - Simple Threadsimplethread.com
- The Linux Kernel Module Programming Guidesysprog21.github.io
- Paths for Referring to an Item in the Module Tree - The Rust Programming Languagedoc.rust-lang.org
- Tao of Node - Design, Architecture & Best Practices | Alex Kondovalexkondov.com
- CoffeeScriptcoffeescript.org
- Documentation | NestJS - A progressive Node.js frameworkdocs.nestjs.com
- What the fuck is a closure? ・ Dan’s JavaScript Glossarywhatthefuck.is
- CBA亞洲區塊鏈學院 - 完整區塊鏈教學平台cbaofficial.com
- Cơ chế hoạt động của javascript và nodejsblog.daovanhung.com