I am writing a simple JavaScript application. The code consists of creating an object deck which can have many nested card objects.
Basically, I wanted to be able to access each card in a deck instance like this:
deck1.card2.method();
I have used the following function to create my deck prototype:
function Deck(){
var cardStack = []
//deck properties & methods
}
function card(){
//card properties methods
}
I've been adding each card to the deck and storing them in the cardStack array, using push and pop methods of JavaScript arrays.
This however does not allow me to access my cards as I wished to do:
deck1.card2.method();
Can anyone point me in the right way to achieve this? Is it possible in JavaScript? Thank you in advance :-)