Javascript - Factory Pattern
var peopleFactory = function(name, age, state){
var temp = {};
temp.age = age;
temp.name = name;
temp.state = state;
temp.printPerson = function(){
console.log(this.name + " " + this.age + ", " + this.state);
};
return temp;
};
var person1 = peopleFactory('Wohhie', 12, 'CA');
var person2 = peopleFactory('Sakib', 23, 'AK');
person1.printPerson();
person2.printPerson();
var peopleConstructor = function(name, age, state){
this.name = name;
this.age = age;
this.state = state;
this.printPerson = function){
console.log( this.name + ", " + this.age + ", " + this.state);
};
};
var person1 = new peopleConstructor('wohhie', 23, 'CA');
var person2 = new peopleConstructor('kim', 23, 'SC');
person1.printPerson();
person2.printPerson();b