Skip to content

Instantly share code, notes, and snippets.

@nsisodiya
Created June 5, 2014 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsisodiya/b8c3de78c68209d6b026 to your computer and use it in GitHub Desktop.
Save nsisodiya/b8c3de78c68209d6b026 to your computer and use it in GitHub Desktop.
Prototype pattern in JavaScript
var Person = function(name, age){
this.setName(name);
this.setAge(age);
};
Person.prototype = {
getName : function(){
return this._name;
},
setName : function(name){
this._name = name;
},
setAge : function(age){
this._age = age;
},
getAge: function(){
return this._age;
},
introduction: function(){
return "Hello World, I am " + this.getName();
}
}
///////////////
var p = new Person("Narendra", 32);
p.introduction();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment