Is it possible to have a object constructor where each objects has its own array?
I am have trouble figuring out the syntax if so.
Right now I am creating objects and a separate array to co-aside the object(waiters) array.
function Waiter (name, orders[]) {
this.name = name;
this.orders = orders;
}
// Constructor for waiter object
function Waiter (name) {
this.name = name;
}
// Waiter objects
var waiterOne = new Waiter('Timo');
var waiterTwo = new Waiter('Lucian');
var waiterThree = new Waiter('Arpi');
// Array to store waiter object
var waiters = [
waiterOne,
waiterTwo,
waiterThree
];
// Count so that the same number of arrays are create as waiters
var countWaiterOrders = waiters.length;
// Creating a order array for each waiter object
for(var i = 0; i <= countWaiterOrders; i++){
var order = [i];
}
Getting error:
Uncaught SyntaxError: Unexpected token [
Is the error message I get when trying to pass an array to the constructor.
The desired result would just be that each Waiter object has its own array for orders.
ex:
console.log(waiters[0]);
Waiter {name: "Timo", orders: []}