A simple class in Javascript
July 18, 2008
//Lets try to make a Dog class
function Dog(name,age,family,address)
{
this.name=name;
this.age=age;
this.family=family;
this.address=address;
}
// Lets have a method
function details()
{
alert(this.name+’ age ‘+this.age+’ is of type ‘+(this.family)+’ + ‘lives at ‘ + address);
}
// Associate the methos to the class Dog prototype
Dog.prototype.details=details;
// Make a reference
dog1=new House(’johnny’,4,’beagle’,'no.1, walkers street’);
// Make the method call
dog1.view();
Entry Filed under: Education, programming, web. .
Trackback this post | Subscribe to the comments via RSS Feed