当前位置:网站首页>module. Exports points to problems

module. Exports points to problems

2022-06-21 17:31:00 Yu'an_ ZhangDe

Let's start with a question

module.exports === exports

  Final , Shared results , It's always module.exports The object that is pointed to  

module.exprots Two directional problems

1、 At the same time point to a

// console.log(exports === module.exports)

const username = 'zs'

module.exports.username = username
exports.age = 20
exports.sayHello = function() {
  console.log(' Hello everyone !')
}

//  Final , Shared results , It's always  module.exports  The object that is pointed to 

Execution results

 

 2、module.export Re point to a new object

//  In a custom module , By default , module.exports = {}

const age = 20

//  towards  module.exports  Object  username  attribute 
module.exports.username = 'zs'
//  towards  module.exports  Object  sayHello  Method 
module.exports.sayHello = function() {
  console.log('Hello!')
}
module.exports.age = age

//  Give Way  module.exports  Point to a new object 
module.exports = {
  nickname: ' Little black ',
  sayHi() {
    console.log('Hi!')
  }
}

Execution results

 

  Final , Shared results , It's always module.exports The object that is pointed to

 

原网站

版权声明
本文为[Yu'an_ ZhangDe]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211517547430.html