Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【2022.8.24】module.exports 和 exports #64

Open
lkzwc opened this issue Aug 26, 2022 · 0 comments
Open

【2022.8.24】module.exports 和 exports #64

lkzwc opened this issue Aug 26, 2022 · 0 comments

Comments

@lkzwc
Copy link
Owner

lkzwc commented Aug 26, 2022

module.export s和 exports 都属于commonJS

  • 每一个JS文件都是一个单独的模块
  • 每个模块都有一个module对象
  • module对象里边有一个exports对象
  • 我们可以吧需要导出的挂载到module.exports上,即module.export.xxx=xxxx
  • node为了方便,每个模块又提供了一个exports对象
  • module.exports.xxx===exports.xxx

用法

//导出多个成员
exports.xxx =a
exports.xx1=b
exports.xx2=c

// 导出单个成员
module.exports="hello"

//导出多个成员
module.exports={
func:()=>{},
demo:"xxxx"
}

下面代码是错误的
module.exports='hello'
module.exports=function(){ return x+y }

@lkzwc lkzwc changed the title 【2022.8.24】module.export 和 export 【2022.8.24】module.exports 和 exports Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant