zoukankan      html  css  js  c++  java
  • 导出模块成员

    使用module.exports对象导出模块成员

    每个模块内部都有一个 module 对象,代表当前模块,我们可以使用它的 exports 属性导出模块成员。该属性的初始值为一个空对象,我们只需要将被导出的成员添加为该对象的属性即可。例如:

     1 // 模块私有的成员
     2 function divide ( x, y ) {
     3     return x / y;
     4 }
     5 
     6 function multiply ( x, y ) {
     7     return x * y;
     8 }
     9 
    10 // 如果我们想导出某个成员的话,只需要将它添加为 module.exports 对象的属性即可。
    11 // 模块导出的成员
    12 module.exports.add = function (x, y) {
    13     return x + y;
    14 };

    module.exports.subtract = function (x, y) {

        return x - y;

    };

    使用module.exports的别名:exports对象

  • 相关阅读:
    [USACO 5.5]Hidden Password
    [Codeforces 1016F]Road Projects
    再会,OI
    [TJOI 2018]智力竞赛
    [POI 2009]Lyz
    [NOI 2015]品酒大会
    [NOI 2017]蔬菜
    [NOI 2017]整数
    [NOI 2017]游戏
    [NOI 2017]蚯蚓排队
  • 原文地址:https://www.cnblogs.com/wszzj/p/12040355.html
Copyright © 2011-2022 走看看