I have searched all over for a comprehensible answer to this very simple question and cannot seem to find one. As a primarily java programmer, this has been a very frustrating process.
For example, say I am trying to program a deck of cards. The way I would do this would be to have a 'Card' class in card.js which would look something like this:
function Card(value, suit){
this.value = value;
this.suit = suit;
}
and then a 'Deck' class in deck.js which would look something like this :
function Deck(){
this.cardArray = [];
this.topCard = new Card(2, 'clubs');
}
Deck.prototype.shuffle = function(){
//shuffle the deck
}
The problem here is that I get an error saying 'Unexpected Identifier'. Presumably because js doesn't realize that I have defined the Card class. How can I make it so the deck.js file can access the Card class?
I should mention that I am doing attempting to do this without a browser, so I think I would then be using node.js (Again, sorry I'm new to this environment). Or perhaps better stated, this will be server side.
Deck.prototype.shuffle = function(){}should not be inside the constructor.'Unexpected Identifier'is a syntax error. The code you posted doesn't throw that error, so you seem to have omitted the part that contains that error. To be clear: If you are not importingCardinto whereverDeckis defined then you will still get an error, but that would be a different error.