Below is my class declaration:
class Category {
constructor(id, name, type, url) {
this.id = id;
this.name = name;
this.type = type;
this.url = url;
this.assets = [];
}
set assets(value) {
this.assets = value;
}
}
To use it in my main class, I imported it as import Category from './beans';
. I tried to create an object of this class using
let category = new Category("1", "2", "3", "4");
An error occurred:
undefined is not a constructor (evaluating 'new _beans.Category("1", "2", "3", "4")')
Is there a way to resolve this issue?
UPDATE: It appears that the error was caused by the presence of the assets
declaration within the constructor of Category
. After removing it, the code worked fine. Now, the question remains on how to store a variable in the Category
class that can be initialized at a later time and not in the constructor.