Monday 5 June 2017

Required modules "gone" when in static method

I am currently building a node.js app and I have encountered a problem I can't seem to solve.

I have two classes Series.js and Episode.js. Whenever I want to make a new Series object, I call a static method on the Series class Series.fromJson(). In this method I call a static method Episode.fromJson() in order to populate the series with its episodes.

However, when I try to call Episode.fromJson() I get an error message saying:

TypeError: Episode.fromJson is not a function,

when indeed it is. I have attempted printing out the Episode class in fromJson()(line 31 and onwards) and this is the output:

[Function: Series]
{}
[Function: buildSeasonEpisodeSearchString]
[Function: EpisodeInfoApi]

All the other required modules/classes seem to work just fine inside this block if code, while Episode seems to have vanished. EpisodeInfoApi is very similar in structure to the Episode class and it shows up just fine. Also, if I inline const Episode = require("./Episode.js") inside Series.fromJson() everything works as expected, but I'd prefer not to do it this way.

Can you guys help me?



via Snikanes

No comments:

Post a Comment