Node.js - use of module.exports as a constructor

后端 未结 5 1941
孤城傲影
孤城傲影 2020-11-30 16:41

According to the Node.js manual:

If you want the root of your module\'s export to be a function (such as a constructor) or if you want to export a c

5条回答
  •  情话喂你
    2020-11-30 17:04

    The example code is:

    in main

    square(width,function (data)
    {
       console.log(data.squareVal);
    });
    

    using the following may works

    exports.square = function(width,callback)
    {
         var aa = new Object();
         callback(aa.squareVal = width * width);    
    }
    

提交回复
热议问题