Thursday, June 14, 2018

JavaScript - Object - Prototype

Below code demonstrates usage of Prototype in JavaScript:

var age = 30;

var person1 = {
  name : "Diana",
  age : 27,
};

console.log(person1.__proto__);

//console.log(person1.anything());

console.log(person1.toString());

Object.prototype.greetings = function() {
  console.log("Hello there!");
}

person1.greetings();


Refer:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype


Practice at:
http://jsbin.com


No comments:

Post a Comment