moringaman
3/7/2017 - 6:04 PM

Basic Person Prototype

Basic Person Prototype

//declare person object


var person = {
  
  name: 'john',
  age: 26,
  details: {
    hobbies:['squash', 'football', 'tennis'],
    location: "Jamaica"
  },
   };

// write a function for the Object prototype

Object.prototype.greeting = function(){
    console.log("hello, my name is: " + this.name + " and I am from " + this.details.location);
  }

// create a person object using the prototype

var jenny = Object.create(person);
jenny.name = "Jenny";

// call the function to reference your modified prototype data

jenny.greeting();