Listing 9.09 - A Place constructor part 1
JS Bin
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());
Listing 9.09 - A Place constructor part 1 - Tasks 1&2
- Add a second place.
- Call the getInfo method on your new place.
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());