nodejs定義函數的方法


test_163:/home/exenode/part3/module_exports # more calc.js
module.exports = {
  sum:function() {
    var result = 0;
    for (var i in arguments) {
      if (!isNaN(arguments[i])){
        result += parseFloat(arguments[i]);
      }
    }
  return result;
  },
};
test_163:/home/exenode/part3/module_exports # more index.js
var calc = require('./calc');

console.log('calc:', calc.sum(1,20,34,-9,56));
test_163:/home/exenode/part3/module_exports #
test_163:/home/exenode/part3/module_exports # node index.js
calc: 102


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM