Tuesday, June 30, 2009

Protype objects using Javascript

I have come across some aritcle for javascript. just thought of sharing this to everyone.so that am writing this in my blog.

let me explain my faurouite Prototype objects in the javascript. If you want to write libraries and learn advance in javascript. please try to learn prototype objects. It will be very use full.


Protytype objects.

Prototype is the keyword, Using this, we can add the custom properties and methods. Let me go through in detail.

Let me explain about custom properties in prototype objects.

function circle()
{
//
}

circle.prototype.pi="3.14";

This PI property is common for all the instances of the methods.


Custom Methods:

function ReverseBack()
{
for(i=this.length-1;i<=0;i--)
{
document.write(this.charAt(i));
}
}

String.Protype.writeBack=ReverseBack();

var message1="Bala";
var message2="alaB";

message1.writeBack();
message2.writeBack();

Output:
alaB;
Bala;