zoukankan      html  css  js  c++  java
  • 288 Node.js模块化开发:js开发弊端,模块的概念,模块成员导出的2种方式及其区别,模块成员导入

    // console.log(112);
    
    const add = (n1, n2) => n1 + n2;
    exports.add = add;
    

    // const a = require('./03.module-a.js');
    const a = require('./03.module-a');
    console.log(a.add(10, 20));  // 30
    console.log(111); // 111
    

    const greeting = name => `hello ${name}`;
    const x = 100;
    exports.x = x;
    module.exports.greeting = greeting;
    
    // 当exports对象和moudle.exports对象指向的不是同一个对象时 以module.exports为准
    module.exports = {
    	name: 'zhangsan'
    }
    
    exports = {
    	age: 20
    }
    

    const a = require('./04.module.exports.js');
    // console.log(a.greeting('zhangsan'));
    console.log(a);  // { name: 'zhangsan' }
    
  • 相关阅读:
    day06
    day05
    day04
    day03
    day02
    day01
    python-study-42
    OI 知识总览 算法篇 之 图论
    OI 知识总览 算法篇 之 基础算法
    [CSP2019-JX] 散步 解题报告
  • 原文地址:https://www.cnblogs.com/jianjie/p/12322526.html
Copyright © 2011-2022 走看看