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. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Blogroll

Category Cloud

ajax books Education free software linux Market opensource open standards OSS programming search servers services Uncategorized web

Archives