CommonJS规范

天祈
2022-08-13 / 0 评论 / 178 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年09月12日,已超过941天没有更新,若内容或图片失效,请留言反馈。

概述

module对象

module.exports属性

require命令

模块的缓存

模块的加载机制

CommonJS与ES6区别

  • CommonJS模块输出的是一个值的复制 ES6模块输出的是值的引用
  • CommonJS模块是运行时加载,ES6模块是编译时输出接口

    // CommonJS
    module.exports = {
    foo:"hello",
    bar:"world"
    }
    // 等同于
    exports.default = {
    foo:"hello",
    bar:"world"
    }
    
    
    exports.foo = 'hello'
    // ES6
    export default {
    foo:"hello",
    bar:"world"
    }
    
    export let foo = 'heool'
0

评论 (0)

取消