How to get two JavaScript classes to talk to each other? I'm a budding JavaScript programmer, working on an exercise where I'm trying to create two classes (Books and Shelf) and need to have a shelf know what books are on it. I'm pretty new to OOP so I know I'm missing a crucial step (or three). I probably already ran off the rails, but any point in the right direction would be greatly appreciated.

&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;title&gt;Library&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;script type="text/javascript"&gt;

//The Books
function Books(title, enshelf, unshelf) {
    this.title = title;
    this.enshelf = enshelf;
    this.unshelf = unshelf;
}

var bookA = new Books('The War of 1812',true,false);
var bookB = new Books('Watership Down',false,true);
var bookC = new Books('Sand Cake',true,false);

//The Shelves
function Shelf (shelfNumber, shelfName) {
    this.shelfNumber = shelfNumber;
    this.shelfName = shelfName;
}

var shelf100 = new Shelf('100','History');
var shelf200 = new Shelf('200','Fiction');
var shelf300 = new Shelf('300','Childrens');

var shelfTotal = [shelf100, shelf200, shelf300];
var bookInventory = [bookA, bookB, bookC];

// List all the books in the library
function displayBooks(book) {
    document.write(book.title + "&lt;br&gt;" + book.shelfName +"&lt;br&gt;&lt;br&gt;");
}

//Show total number of books
var showBooks = function() {
    for(i=0; i &lt; bookInventory.length; i++) {
        displayBooks(bookInventory[i]);
    }
}

showBooks();
document.write("Total number of books: " + bookInventory.length);

&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
There are multiple ways of handling this. If you can pass the Books you want to the Shelf object, that would be probably one of the easiest methods.

//The Shelves
function Shelf (shelfNumber, shelfName) {
    this.shelfNumber = shelfNumber;
    this.shelfName = shelfName;
    this.books = new Array();
    this.addBook = function(book) {
        this.books[this.books.length] = book;
    }
    this.displayBooks = function() {
        for(i=0; i &lt; this.books.length; i++) {
            displayBooks(this.books[i]);
        }
    }
}

// then you can use it like this...

shelf100.addBook(bookA);
shelf100.addBook(bookB);
shelf100.addBook(bookC);

shelf100.displayBooks();