当前位置:网站首页>module.exports指向问题
module.exports指向问题
2022-06-21 16:04:00 【玉安_ZhangDe】
首先说一个问题
module.exports === exports最终,向外共享的结果,永远都是 module.exports 所指向的对象
module.exprots 两种指向问题
1、同时指向一个
// console.log(exports === module.exports)
const username = 'zs'
module.exports.username = username
exports.age = 20
exports.sayHello = function() {
console.log('大家好!')
}
// 最终,向外共享的结果,永远都是 module.exports 所指向的对象
执行结果
![]()

2、module.export重新指向一个新的对象
// 在一个自定义模块中,默认情况下, module.exports = {}
const age = 20
// 向 module.exports 对象上挂载 username 属性
module.exports.username = 'zs'
// 向 module.exports 对象上挂载 sayHello 方法
module.exports.sayHello = function() {
console.log('Hello!')
}
module.exports.age = age
// 让 module.exports 指向一个全新的对象
module.exports = {
nickname: '小黑',
sayHi() {
console.log('Hi!')
}
}执行结果
![]()
最终,向外共享的结果,永远都是 module.exports 所指向的对象
边栏推荐
猜你喜欢

NLog自定义Target之MQTT

Exness: the impact of inflation in the United States is too great, and the leaders of the Federal Reserve have expressed their position one after another

Stack growth direction and memory growth direction

QT knowledge: using the qgraphicspixmapitem class

Beaucoup de sociétés de logiciels sont en fait des "blagues"

The new razor component supports proxy connection to RDP, and jumpserver fortress v2.23.0 is released

2022年第三届全国运筹学/数据、模型与决策课程教学研讨会通知

MATLAB实现的基于对称TSP问题研究

Nanjing University static program analyses -- Introduction learning notes

【毕业N年系列】 毕业第四年
随机推荐
Yaml data driven demo
Hairui technology completed the pre-A round of financing of tens of millions of yuan to build the first artificial intelligent distribution Internet of things in China
从北京“润”到芝加哥,工程师宝玉“滋润”成长的秘诀
[MySQL learning notes 19] multi table query
【mysql学习笔记19】多表查询
Kotlin 中list set map
牛客网:大数加法
【没搞懂路由策略?盘它!】
大话内存四区
QT5知识:字符串列表QStringListModel
The new razor component supports proxy connection to RDP, and jumpserver fortress v2.23.0 is released
一些细节
3M互助智能合约系统开发搭建技术
PowerPoint tutorial, how to change page orientation and slide size in PowerPoint?
线段树&树状数组模板
【Leetcode】297. 二叉树的序列化与反序列化 (困难)
Comparison of UDP and TCP
导数常用公式__不定积分常用公式
[MySQL learning notes 15] user management
Implementation of decode function in GP