使用来自NodeJS中另一个模块的属性

我有这个名为myService.js的文件,我使用加热或冷却系统来定义季节。 在南半球的国家(例如澳大利亚),季节倒过来的情况下,情况尤其不同:

const myService= {}; const yearTimes = { JapanDefault: { heat: new YearTime('heat', 'Sep', 15, 'Mar', 1), cool: new YearTime('cool', 'Mar', 14, 'Sep', 14) }, AustraliaDefault: { heat: new YearTime('heat', 'Jul', 1, 'Aug', 31), cool: new YearTime('cool', 'Sep', 1, 'Mar', 1) } }; myService.gettingAnalysis = function (site, Key) { return Promise.all([ myService.findingHeat(site, Key), myService.findingCool(site, Key) ]).spread(function (heat, cool) { return { heating: heating, cooling: cooling }; }); }; myService.findingHeat = function (site, Key) { return Promise.resolve(YearTime[Key] && YearTime[Key]['heat'] || defaults['heating']); }; module.exports = myService; 

在另一个文件中,我必须检查不同的情况,例如,如果在夏天使用暖气,我应该显示一个警告。 该规范对北半球工作正常,但对于南半球来说是错误的,因为它发现在夏季(五月,六月)使用加热系统,但是在那个特定情况下,那个冬季是在该地区。 这是第二个名为Breakdown.js的文件:

 const _ = require('underscore'); const util = require('util'); const stats = require('simple-statistics'); const myService = require('./myService'); const SUM = 10; ... check('must not indicate heating in summer', function (report) { const model = report.findSection('Breakdown').model; const heatingSeries = _.findWhere(model.series, { name: 'Space heating' }); if (!heatingSeries || model.series.length === 1) { return; } const totalAccounts = _.size(report.asModel().accountNumbers); // TODO: "summer" varies per cohort const warnings = _.compact(_.map(['May', 'Jun'], function (monthLabel) { const summerIndex = _.indexOf(model.xAxisLabels, monthLabel); const heatingSummerCost = heatingSeries.data[summerIndex]; if (heatingSummerCost > (totalAccounts * SUM)) { return { month: monthLabel, cost: heatingSummerCost, accounts: totalAccounts }; } })); this.should(!warnings.length, util.format('heating in summer recommended')); }) ... 

我试图做的是用myService.findingHeat(site, key)myService.seasons.AustraliaDefaultreplace['May', 'Jun'] ,以便检测它是否不在该区域的夏天,并且是正常的有采暖成本。 有没有人有任何想法如何解决这个问题?

您试图用由myService.findingHeatingSeason(report.site, report.cohort)myService.seasons.AustraliaDefault返回的季节对象来replace数组['July', 'Aug'] ,这可能会导致一些不一致。 你能指定你季节构造吗?