Featured Post

Three ways of defining JavaScript classes

First Way:

function Apple(name,color)
{
this.name=name;
this.color=color;
this.getData=function(){
alert(this.name+":"+this.color);
}
}

var a=new Apple("Hey","red");

a.getData();


Advantage:

This way is normal way of defining objects . this is really useful and can
give onstructor option to the end user

Second Way:

var apple={

name:'heyyyyy',
color:'blue',
getData:function(){
alert(this.color+":"+this.name);
}
}

apple.getData();

Advantage:

This is direct way of defining object , here is no constructor option and
If you want to limit the class to singleton then go for this

Third Way:


var apple1= new function(name,color){

this.type=name;
this.color=color,
this.getData=function(){
alert(this.color+":"+this.type);
}

}

apple1.type="MMMM";
apple1.color="Red";

apple1.getData();

Advantage:

This is mixed way of above two ways . Here it is also singleton kind of
class . But there you can execute constructor only once .
As you are not giving the class name

Thanks
sitaram PV

This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit us at http://www.polaris.co.in

Comments