Node module.exports returns undefined

后端 未结 3 2045
滥情空心
滥情空心 2021-01-19 00:55

I am having an issue with Node.js and module.exports. I understand that module.exports is a call to return an object, that object having whatever p

3条回答
  •  鱼传尺愫
    2021-01-19 01:48

    Try this:

    module formatting:

    function Format() {
        this.setter = function(text) {
          this.text = text;
        }
        this.show = function() {
          console.log(this.text);
        } 
    }
    //this says I want to return empty object of Format type created by Format constructor.
    
    module.exports = new Format();
    

    index.js

    var formatting = require('./formatting');
    formatting('Welcome');
    console.log(formatting.show());
    

提交回复
热议问题