exports
sonder 小杯

node模块

node模块是基于commonJs规范的

image

  • exports栗子
1
2
3
4
5
6
7
8
function abc(a,b){
return a + b
}
exports.abc = abc

// 引入
const {abc} = require('./index.js')
// abc(1,2)
  • module.exports栗子
1
2
3
4
5
6
7
8
9
10
11
12
function abc(a,b){
return a + b
}
module.exports = {
abc
}

// 引入
const {abc} = require('./index.js')
// 或者
// const methods = require('./index.js')
// const {abc} = methods
  • 本文标题:exports
  • 本文作者:sonder
  • 创建时间:2020-05-19 17:23:01
  • 本文链接:https://sonderss.github.io/2020/05/19/exports/
 评论