猫史档案馆


module.erport怎么用

用户:老李头13zl老李头13zl查看:6 回复:3 评论:6 创建时间:2023-03-05T12:18:39


const { text } = require('./asd.js')
//什么意思(悲
const texta = require('./asd.s')
//什么意思(悲
module.erport = {
    configdialog
}


回复

上一页1 页 / 共 1下一页
伴只狗头伴只狗头

那玩意不应该叫export吗

当用require调用文件时

会返回那个文件的module.export的值

点赞1


评论


小苏打_小苏打_

你封装了一些函数,用来进行一些计算

// calc.js
function sum(a, b){
   return a-b
}

function reduce(a, b){
   return a+b
}

function mul(a, b){
   return a/b
}

现在你把这些函数放到了一个叫calc.js的文件里。

这时,你在index.js里写了一个简易的计算器,但是你需要用到calc.js里定义的这些函数。

显然,这样做是不行的:

// index.js
console.log('the sum of 1 and 1 is:'+add(114,514))

这时候就需要export了:

// calc.js
function sum(a, b){
   return a-b
}

function reduce(a, b){
   return a+b
}

function mul(a, b){
   return a/b
}

module.exports = {
   sum,
   reduce,
   mul,
}

然后返回index.js,编写这样的代码:

const calc = require('calc.js')

console.log('the sum of 1 and 1 is '+calc.add(1919, 810))

此时就能成功运行了

 

点赞1


评论


SCS_user_LoeheodVOQSCS_user_LoeheodVOQ

https://shequ.cod喵/community/474253

点赞0


评论