ProtoType Design Pattern in JS

by Rajdeep Chandra

JavaScript

var Person = function(firstName,lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

  Person.prototype.fullName = function(){
    return "My Name is " + this.firstName + " " + this.lastName;
  }

var newObject1 = new Person('rajdeep', 'chandra')
document.write(newObject1.fullName());

var newObject2 = new Person('subhodeep', 'chandra')
document.write(newObject2.fullName());