node 模块正确暴露方法


一个node模块,为了能够服用,就需要将其暴露,那么如何正确写呢?(参考:https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Express_Nodejs/Introduction

【正确写法A】

exports.area = width => { return width * width; };
exports.perimeter = width => { return 4 * width; };

【正确写法B】

module.exports.area = width => { return width * width; };
module.exports.perimeter = width => { return 4 * width; };

【正确写法C】

// 这种写法只能用 module.exports
module.exports = {
  area: width => { return width * width; },
  perimeter: width => { return 4 * width; }
};

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM