Get Programming with JavaScript - Listing 9.09

Listing 9.09 - A Place constructor part 1

var Place = function (title, description) { this.title = title; this.description = description; this.getInfo = function () { var infoString = this.title + "\n"; infoString += this.description + "\n"; return infoString; }; }; var library = new Place( "The Old Library", "You are in a library. Dusty books line the walls." ); console.log(library.getInfo());

Further Adventures

Listing 9.09 - A Place constructor part 1 - Tasks 1&2

var Place = function (title, description) { this.title = title; this.description = description; this.getInfo = function () { var infoString = this.title + "\n"; infoString += this.description + "\n"; return infoString; }; }; var library = new Place( "The Old Library", "You are in a library. Dusty books line the walls." ); console.log(library.getInfo()); // a second place var kitchen = new Place( "The Kitchen", "You are in a kitchen. There is a disturbing smell." ); console.log(kitchen.getInfo());