zoukankan      html  css  js  c++  java
  • Node中的模块系统

    加载require

    var 自定义变量名称 = require('模块')

    两个作用:

    执行被加载模块的代码

    得到被加载模块中的exports导出接口对象

    导出exports

    node中是模块作用域,默认文件中所有成员只在当前文件模块有效

    对于希望可以被其他模块访问的成员,我们就把这些成员都挂载到exports接口对象中就可以了。


    导出单个成员(拿到的就是:函数,字符串)

    module.exports = 'hello'

    导出多个成员(必须在对象中)

    module.exports={

    add:function(){

    return x + y

    },

    str:'hello'

    }

  • 相关阅读:
    053705
    053704
    053703
    053702
    053701
    053700
    053699
    053698
    053697
    HDU 3746 Cyclic Nacklace
  • 原文地址:https://www.cnblogs.com/Yanss/p/10459543.html
Copyright © 2011-2022 走看看