I have two files:
let WordPair = function(wordA, wordB) {
function doSomething() { ... };
const smth = wordA + wordB;
return {doSomething, smth};
};
module.exports = WordPair;
-
let wordpair = require('./WordPair.js')('dog', 'cat');
wordpair.doSomething();
Now that works fine, but what I want to do is creating many instances of WordPair, for example like this:
let arr = [];
for (let i = 0; i < 10; i++) {
arr.push(new WordPair('xyz', 'abc'));
}
In other words: How you would use instances of a class in Java. What's the correct way to achieve this in Javascript?