Thursday, 20 April 2017

Promise has "Variable declaration expected." error

I'm a new user of Promises in JavaScript and I have the following code snippet:

const arrayToTest;
let c = seasonalityService.gettingSeasonalityAnalysis(report.site, report.template.cohortKey)
    .then(function (result) {
        let date = moment();
        console.log(result.heating.getSeasonMonths(date));
        arrayToTest = result.heating.getSeasonMonths(date);
        console.log(result.cooling.getSeasonMonths(date));    

    })
    , function (error) {
        console.error('an error occured!!!', error);
    };

I have seasonalityService.js where I have gettingSeasonalityAnalysis method:

seasonalityService.gettingSeasonalityAnalysis = function (site, cohortKey) {
    return Promise.all([
        seasonalityService.findingHeatingSeason(site, cohortKey),
        seasonalityService.findingCoolingSeason(site, cohortKey)
    ]).spread(function (heating, cooling) {
        return { heating: heating, cooling: cooling };
    });
};

I tested the first part in similar situation and it worked fine but now before I compile the code if I hover over function (error) it says [js] Variable declaration expected.

I don't understand what variable does it need.



via migea

No comments:

Post a Comment