CommonJS规范

一、以下模块加载机制被称为CommonJS规范

  hello.js
        var s = "我爱";
        function lin(name){
            console.log(s + name)
        }
        module.exports = lin //在模块中对外输出变量

  main.js
        var linlin = require("./hello")//引入hello.js(其他)模块输出的对象
        var sn = "chinese";
        linlin(sn)

node.js运行main.js控制台显示如下

posted @ 2020-09-17 10:49  onceweb  阅读(101)  评论(0编辑  收藏  举报