I have a JavaScript class defined as shown here:
function Item() {
this.init();
}
Item.prototype = {
id: null,
name: '',
description: '',
init: function () {
this.id = "1";
}
};
I want to add a property called "logs". I want this property to be an array of other class entities. How do I define this kind of array as a property on my Item class? How do I add entities to that array? Originally, I thought I could add "this.logs = {};" in my init function. Then in my code elsewhere, I tried the following:
Item i = new Item();
i.logs.push(NewLog());
However, the push function through an error that says: "Cannot call method 'push' of undefined"
What am I doing wrong?