Object Oriented JavaScript

<script language="JavaScript">
function Person(first, last) {
	this.init(first, last);
}
Person.prototype.init = function(first, last) {
    this.first = first;
    this.last  = last;
};
Person.prototype.toString = function() {
	return this.first + " " + this.last;
}
Employee.prototype = new Person();
Employee.prototype.constructor = Employee;
Employee.superclass = Person.prototype;
function Employee(first, last, id) {
	Employee.superclass.init.call(this, first, last);
	this.id = id;
}
Employee.prototype.toString = function() {
	var name = Employee.superclass.toString.call(this);
	return this.id + ": " +  name;
}
var person = new Person("Muneeb", "Ahmad");
alert(person);
var employee = new Employee("Kevin", "Johnson", 1001);
alert(employee);
</script>

You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

AddThis Social Bookmark Button

Similar Posts

Comments are closed.