##Creating an object##
- Object Constructor => Create several similar objects => Classes
- Literal constructor => One object of a kind
- Function constructor
- Protoype Based
- Function and Prototype Based
- Singleton Based
1.) Object constructor
var person = new Object();
person.name = "Anand",
person.getName = function(){
return this.name ;
};
2.) Literal constructor
var person = {
name : "Anand",
getName : function (){
return this.name
}
}
3.) Function Constructor
function Person(name){
this.name = name
this.getName = function(){
return this.name
}
}
4.) Prototype
function Person(){};
Person.prototype.name = "Anand";
5.) Function/Prototype combination
function Person(name){
this.name = name;
}
Person.prototype.getName = function(){
return this.name
}
6.) Singleton
var person = new function(){
this.name = "Anand"
}