JSFiddle - React, Tailwind, and code Playground

by deepak sisodiya

JavaScript

// The prototype property allows you to add 
// 1. properties to an object
// 2. methods to an object

var alert  = function (str) {
   var st = document.createTextNode(str);
   var p = document.createElement('p');
   p.appendChild(st);
   document.querySelector('body').appendChild(p);
}

function person(firstName,lastName) {
    this.firstName = firstName,
    this.lastName = lastName
}

var obj = new person("deepak","sisodiya")

person.prototype.address = "Indore"
alert(obj.address)

person.prototype.fullName = function() {
    return this.firstName + " " + this.lastName
}
alert(obj.fullName())

// fullName is property of the prototype object but it behaves as it is property of obj Object

alert(obj.hasOwnProperty('firstName'))   
// display true because firstName is property of obj Object

alert(obj.hasOwnProperty('fullName'))
// display false because fullname is property of prototype object