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