Javascript object orientation Javascript does not use classes. Javascript uses prototype-based programming. Already existing objects are expanded ("decorated"). // A function to reate a custom object function Book (authorName, title, ISBN, pubDate) { this.author = authorName; this.title = title; this.ISBN = ISBN; this.date = pubDate; this.toString = BookToString; this.setTitle = BookSetTitle; } // setting methods function BookToString() { var s=""; s = this.author + " " + this.title + " " + this.ISBN + " " +this.date; return s; } function BookSetTitle(title) { this.title = title; } // instantiating an object: var text = new Book ("Heilmnn", "JavaScript with DOM...", "123", new Date("January 1, 2000")); // expanding on the custom object (all future instatiated objects with have cost: Book.prototype.cost = "five dollars"; // "" is the default value // decorating a current object (only this object will now have rating. text.rating = "3 stars"; text.printRating = function() { alert(text.rating); }; /***********************************************************************/ // So, here is a custom object: var Animal = function() {}; // instantiate an instance: var pet1 = new Animal(); // Add a property to Animal Animal.prototype.species = "something"; // Add a method to Animal Animal.prototype.setSpecies = function(p) { this.species = p; } // Add a different method to Animal (notice the property is created here) Animal.prototype.setName = function(p) {this.name = p; } /***********************************************************************/ Animal.prototype.toString = function() { var s = ""; s = this.name + " " + this.species; return s; } var pet2 = new Animal(); pet2.setSpecies("dog"); pet2.setName("Ada"); alert("pet2: " + pet2.toString() ); // can decorate an object without decorating all pet2.cuteness = "very cute"; alert("pet2.cuteness: " + pet2.cuteness);