This is my code:
var Evalcard = function(number) {
if (number == 1) {
this.name = "Ace";
this.value = 11;
}
else if (number == 11) {
this.name = "Jack";
this.value = 10;
}
else if (number == 12) {
this.name = "Queen";
this.value = 10;
}
else if (number == 13) {
this.name = "King";
this.value = 10;
}
return [this.name,this.value];
}
var Buildmatrix = function(mat,suit) {
row = [];
var cardeval = new Evalcard(r);
for (r = 1;r <= 13;r++) {
cardeval(r);
row[r] = [r,cardeval(r)[0],suit,cardeval(r)[1]]
mat.push(row);
}
return row;
}
Is my use of the constructor here correct? can I call an instance of Evalcard() by placing the arguments next to the new object (in this case var cardeval)?
Your “Evalcard()” constructor returns an array. You cannot make a function call to an array; it doesn’t make sense.
I think what you want is just:
(Note also that I added back some missing
varkeywords — don’t forgetvar!)Since you’re returning an array anyway, there’s no reason to treat it as a constructor.