topical media & game development
#javascript-code-01-objects.js / js
// The constructor for our 'Lecture'
// Takes two strings, name and teacher
function Lecture( name, teacher ) {
// Save them as local properties of the object
this.name = name;
this.teacher = teacher;
}
// A method of the Lecture class, used to generate
// a string that can be used to display Lecture information
Lecture.prototype.display = function(){
return this.teacher + " is teaching " + this.name;
};
// A Schedule constructor that takes in an
// array of lectures
function Schedule( lectures ) {
this.lectures = lectures;
}
// A method for constructing a string representing
// a Schedule of Lectures
Schedule.prototype.display = function(){
var str = "";
// Go through each of the lectures, building up
// a string of information
for ( var i = 0; i < this.lectures.length; i++ )
str += this.lectures[i].display() + " ";
return str;
};
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.