当前位置:网站首页>Use between nodejs modules
Use between nodejs modules
2022-04-23 16:58:00 【Endless cake】
practice
Separately build A,B,C Three independent js modular .
A Module implementation summation
B Module implementation average
C Module reference B modular , At the same time, complete the process of first summing and then averaging
A modular
//eval() Function to evaluate a string , And execute the JavaScript Code .
module.exports={ // Declare the module component first
sum(...arg){ // use ES6 Extension operator , Put all received parameters into a set
return eval(arg.join('+')) // Connection string , And calculate
}
}
B modular :
// First introduce A modular
let A = require('./a') // Be sure to add. ./ Suffixes can be omitted
module.exports={ // Declare the module component first
avg(...arg){ //( here arg Will be C An array passed from the component )
// Expand each item in an array through the expansion operator , Pass them on to sum, Then divide by the length of the array
return A.sum(...arg) / arg.length
}
C modular :
let B = require('./b')
console.log(B.avg(12,23,34,45,56,67,78,89))
Then execute directly through the command line C.js
版权声明
本文为[Endless cake]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554520133.html
边栏推荐
- 【解决报错】Error in v-on handler: “TypeError: Cannot read property ‘resetFields’ of undefined”
- Getting started with JDBC
- Project framework of robot framework
- Construction of promtail + Loki + grafana log monitoring system
- vscode如何比较两个文件的异同
- 详解牛客----手套
- Detailed explanation of information abstract, digital signature, digital certificate, symmetric encryption and asymmetric encryption
- Decimal format decimal / datetime conversion processing
- Solution architect's small bag - 5 types of architecture diagrams
- Rtklib 2.4.3 source code Notes
猜你喜欢
Detailed explanation of Niuke - Gloves
信息摘要、数字签名、数字证书、对称加密与非对称加密详解
Dancenn: overview of byte self-developed 100 billion scale file metadata storage system
面试百分百问到的进程,你究竟了解多少
详解牛客----手套
Installing labellmg tutorial in Windows
如何建立 TikTok用户信任并拉动粉丝增长
PyMySQL
English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
[PROJECT] small hat takeout (8)
随机推荐
Installing labellmg tutorial in Windows
◰GL-阴影贴图核心步骤
CentOS MySQL multi instance deployment
Blue Bridge Cup provincial road 06 -- the second game of the 12th provincial competition
Introduction to new functions of camtasia2022 software
SPC introduction
Detailed explanation of information abstract, digital signature, digital certificate, symmetric encryption and asymmetric encryption
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
手写事件发布订阅框架
Detailed explanation of Milvus 2.0 quality assurance system
Sub database and sub table & shardingsphere
[problem solving] [show2012] random tree
面试百分百问到的进程,你究竟了解多少
5-minute NLP: text to text transfer transformer (T5) unified text to text task model
Paging SQL
Customize my_ Strcpy and library strcpy [analog implementation of string related functions]
ByteVCharts可视化图表库,你想要的我都有
Camtasia2022软件新增功能介绍
Loggie source code analysis source file module backbone analysis