<style>
 body {
 font-family: Consolas, Monaco, "Courier New", monospace;
 font-size: 11px;
 }

 pre {
 white-space: pre-wrap;
 /* Since CSS 2.1 */
 white-space: -moz-pre-wrap;
 /* Mozilla, since 1999 */
 white-space: -pre-wrap;
 /* Opera 4-6 */
 white-space: -o-pre-wrap;
 /* Opera 7 */
 word-wrap: break-word;
 /* Internet Explorer 5.5+ */
 background-color: #eee;
 padding: 15px;
 border-radius: 5px;
 }
</style>

<script type="text/javascript" src="jQuery_v3.6.0.js"></script>
<div style="font-family: Consolas, monospace; font-size: 11px;">

 <h1>Object Oriented Programming</h1>
 <hr />
 <hr />

 <h3>Object</h3>
 Objects are tangible things people can observe and interact with.
 These qualities, or properties, define what makes up an object.
 Note that similar objects share the same properties, but may have different values for those properties.

 <script type="text/javascript">
 $(document).ready(function () {
 console.log("a2rp: object oriented programming");
 let object_1 = {
 name: "Ashish Ranjan",
 date: "April 26, 2022"
 };
 console.log(object_1); // {name: 'Ashish Ranjan', date: 'April 26, 2022'}
 });
 </script>
 <pre>
 let object_1 = {
 name: "Ashish Ranjan",
 date: "April 26, 2022"
 };
 console.log(object_1); // {name: 'Ashish Ranjan', date: 'April 26, 2022'}
</pre>

 <hr />
 <hr />
 <h3>access objects</h3>
 <hr />
 <hr />
 <script type="text/javascript">
 $(document).ready(function () {
 console.log("access object properties");
 let object_1 = {
 name: "Ashish Ranjan",
 date: "April 26, 2022"
 };
 console.log(`name: ${object_1.name} and date: ${object_1.date}`); // name: Ashish Ranjan and date: April 26, 2022
 });
 </script>
 <pre>
 let object_1 = {
 name: "Ashish Ranjan",
 date: "April 26, 2022"
 };
 console.log(`name: ${object_1.name} and date: ${object_1.date}`); // name: Ashish Ranjan and date: April 26, 2022
</pre>

 <hr />
 <hr />
 <h3>method of an object</h3>
 <hr />
 <hr />
 <script type="text/javascript">
 $(document).ready(function () {
 let object_1 = {
 name: "Ashish Ranjan",
 date: "April 26, 2022",
 get_data: function () { return `function inside object: name: ${object_1.name} and date: ${object_1.date}`; },
 };
 console.log(`object_1.get_data():: ${object_1.get_data()}`); // object_1.get_data():: function inside object: name: Ashish Ranjan and date: April 26, 2022
 });
 </script>
 <pre>
 let object_1 = {
 name: "Ashish Ranjan",
 date: "April 26, 2022",
 get_data: function() { return `function inside object: name: ${object_1.name} and date: ${object_1.date}`; },
 };
 console.log(`object_1.get_data():: ${object_1.get_data()}`); // object_1.get_data():: function inside object: name: Ashish Ranjan and date: April 26, 2022
</pre>

 <hr />
 <hr />
 <h3>this keyword</h3>
 <hr />
 <hr />
 <script type="text/javascript">
 $(document).ready(function () {
 let object_1 = {
 first_name: "Ashish",
 last_name: "Ranjan",
 get_data: function () { return `first_name: ${this.first_name} and last_name: ${this.last_name}`; },
 };
 console.log(`object_1 returns from function: ${object_1.get_data}`); // object_1 returns from function: function() { return `first_name: ${this.first_name} and last_name: ${this.last_name}`; }
 });
 </script>
 <pre>
 let object_1 = {
 first_name: "Ashish",
 last_name: "Ranjan",
 get_data: function() { return `first_name: ${this.first_name} and last_name: ${this.last_name}`; },
 };
 console.log(`object_1 returns from function: ${object_1.get_data}`); // object_1 returns from function: function() { return `first_name: ${this.first_name} and last_name: ${this.last_name}`; }
</pre>

 <hr />
 <hr />
 <h3>constructors</h3>
 <hr />
 <hr />
 Constructors are functions that create new objects.
 They define properties and behaviors that will belong to the new object.
 They are a blueprint for the creation of new objects.
 <script>
 $(() => {
 function constructor_function() {
 this.first_name = "Ashish";
 this.last_name = "Ranjan";
 }
 });
 </script>
 <pre>
 function constructor_function() {
 this.first_name = "Ashish";
 this.last_name = "Ranjan";
 }
</pre>

 <hr />
 <hr />
 <h3>create objects with constructors</h3>
 <hr />
 <hr />
 <script type="text/javascript">
 $(() => {
 console.log("create objects with constructors");

 function constructor_function() {
 this.name = "Ashish Ranjan";
 this.date = "April 26, 2022";
 this.get_data = () => { return `this.name: ${this.name} and thie.date: ${this.date}` };
 }
 let test_variable = new constructor_function();
 test_variable.name = "new name";
 console.log(`object values are: ${test_variable.get_data()}`); // object values are: this.name: new name and thie.date: April 26, 2022
 });
 </script>
 <pre>
 function constructor_function() {
 this.name = "Ashish Ranjan";
 this.date = "April 26, 2022";
 this.get_data = ()=>{return `this.name: ${this.name} and thie.date: ${this.date}`};
 }
 let test_variable = new constructor_function();
 test_variable.name = "new name";
 console.log(`object values are: ${test_variable.get_data()}`); // object values are: this.name: new name and thie.date: April 26, 2022
</pre>

 <hr />
 <hr />
 <h3>constructors receive arguments</h3>
 <hr />
 <hr />

 <script type="text/javascript">
 $(() => {
 function constructor_arguments(first_name, last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 }
 let variable_1 = new constructor_arguments("Ashish", "Ranjan");
 let variable_2 = new constructor_arguments("first_name", "second_name");
 console.log(`variable 1 first name: ${variable_1.first_name} second name: ${variable_1.last_name}`); // variable 1 first name: Ashish second name: Ranjan
 console.log(`variable 2 first name: ${variable_2.first_name} second name: ${variable_2.last_name}`); // variable 2 first name: first_name second name: second_name
 });
 </script>
 <pre>
 function constructor_arguments(first_name,last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 }
 let variable_1 = new constructor_arguments("Ashish","Ranjan");
 let variable_2 = new constructor_arguments("first_name","second_name");
 console.log(`variable 1 first name: ${variable_1.first_name} second name: ${variable_1.last_name}`); // variable 1 first name: Ashish second name: Ranjan
 console.log(`variable 2 first name: ${variable_2.first_name} second name: ${variable_2.last_name}`); // variable 2 first name: first_name second name: second_name
</pre>

 <hr />
 <hr />
 <h3>instanceof operator</h3>
 <hr />
 <hr />
 <script type="text/javascript">
 $(() => {
 // let object_1 = (full_name,date) => {
 // this.full_name = full_name;
 // this.date = date;
 // };
 // above object_1 is not a constructor
 let object_1 = function (full_name, date) {
 this.full_name = full_name;
 this.date = date;
 };
 let variable_1 = new object_1("Ashish Ranjan", "April 06, 2022");
 let object_2 = function (first_name, last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_2 = new object_2("Ashish", "Ranjan");
 console.log(`variable_1 instance of object_1:: ${variable_1 instanceof object_1}`); // variable_1 instance of object_1:: true
 console.log(`variable_2 instance of object_1:: ${variable_2 instanceof object_1}`); // variable_2 instance of object_1:: false
 console.log(`variable_1 instance of object_2:: ${variable_1 instanceof object_2}`); // variable_1 instance of object_2:: false
 console.log(`variable_2 instance of object_2:: ${variable_2 instanceof object_2}`); // variable_2 instance of object_2:: true
 });
 </script>
 <pre>
 // let object_1 = (full_name,date) => {
 // this.full_name = full_name;
 // this.date = date;
 // };
 // above object_1 is not a constructor
 let object_1 = function (full_name,date) {
 this.full_name = full_name;
 this.date = date;
 };
 let variable_1 = new object_1("Ashish Ranjan", "April 06, 2022");
 let object_2 = function (first_name,last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_2 = new object_2("Ashish","Ranjan");
 console.log(`variable_1 instance of object_1:: ${variable_1 instanceof object_1}`); // variable_1 instance of object_1:: true
 console.log(`variable_2 instance of object_1:: ${variable_2 instanceof object_1}`); // variable_2 instance of object_1:: false
 console.log(`variable_1 instance of object_2:: ${variable_1 instanceof object_2}`); // variable_1 instance of object_2:: false
 console.log(`variable_2 instance of object_2:: ${variable_2 instanceof object_2}`); // variable_2 instance of object_2:: true
</pre>

 <hr />
 <hr />
 <h3>own property</h3>
 <hr />
 <hr />
 <script type="text/javascript">
 $(document).ready(function () {
 let object_1 = function (first_name, last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_1 = new object_1("ashish1", "ranjan1");
 let variable_2 = new object_1("ashish2", "ranjan2");

 let variable1_properties_array = [];
 for (let property in variable_1) {
 if (variable_1.hasOwnProperty(property)) {
 variable1_properties_array.push(property);
 }
 }
 console.log(`variable1_properties_array:: "${variable1_properties_array}"`); // variable1_properties_array:: "first_name,last_name"
 });
 </script>
 <pre>
 let object_1 = function (first_name,last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_1 = new object_1("ashish1","ranjan1");
 let variable_2 = new object_1("ashish2","ranjan2");

 let variable1_properties_array = [];
 for (let property in variable_1) {
 if (variable_1.hasOwnProperty(property)) {
 variable1_properties_array.push(property);
 }
 }
 console.log(`variable1_properties_array:: "${variable1_properties_array}"`); // variable1_properties_array:: "first_name,last_name"
</pre>

 <hr />
 <hr />
 <h3>prototype properties to reducew duplicate code</h3>
 <hr />
 <hr />
 All JavaScript objects inherit properties and methods from a prototype.
 The prototype is as a "recipe" for creating objects.
 <script type="text/javascript">
 $(document).ready(function () {
 console.log("\n\nprototype properties to reduce duplicate code");

 let object_1 = function (first_name, last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_1 = new object_1("Ashish1", "Ranjan1");
 let variable_2 = new object_1("Ashish2", "Ranjan2");
 object_1.prototype.place = "Bengaluru";
 console.log(`variable_1 values = ${JSON.stringify(variable_1)} and prototype place: ${variable_1.place}`); // variable_1 values = {"first_name":"Ashish1","last_name":"Ranjan1"} and prototype place: Bengaluru
 console.log(`variable_2 values = ${JSON.stringify(variable_2)} and prototype place: ${variable_2.place}`); // variable_2 values = {"first_name":"Ashish2","last_name":"Ranjan2"} and prototype place: Bengaluru
 });
 </script>
 <pre>
 let object_1 = function(first_name,last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_1 = new object_1("Ashish1","Ranjan1");
 let variable_2 = new object_1("Ashish2","Ranjan2");
 object_1.prototype.place = "Bengaluru";
 console.log(`variable_1 values = ${JSON.stringify(variable_1)} and prototype place: ${variable_1.place}`); // variable_1 values = {"first_name":"Ashish1","last_name":"Ranjan1"} and prototype place: Bengaluru
 console.log(`variable_2 values = ${JSON.stringify(variable_2)} and prototype place: ${variable_2.place}`); // variable_2 values = {"first_name":"Ashish2","last_name":"Ranjan2"} and prototype place: Bengaluru
</pre>

 <hr />
 <hr />
 <h3>iterate over object properties</h3>
 <hr />
 <hr />
 <script type="text/javascript">
 $(document).ready(function () {
 console.log("\n\niterate object properties");

 let object_1 = function (first_name, last_name) {
 this.first_name = first_name; // own property
 this.last_name = last_name; // own property
 };
 object_1.prototype.place = "bengaluru"; // prototype property
 object_1.prototype.country = "india"; // prototype property
 let variable_1 = new object_1("ashish", "ranjan");

 let own_property = [];
 let prototype_property = [];
 for (let property in variable_1) {
 if (variable_1.hasOwnProperty(property)) {
 own_property.push(property);
 } else {
 prototype_property.push(property);
 }
 }
 console.log(`own properties:: ${JSON.stringify(own_property)}`); // own properties:: ["first_name","last_name"]
 console.log(`prototype properties:: ${JSON.stringify(prototype_property)}`); // prototype properties:: ["place","country"]
 });
 </script>
 <pre>
 let object_1 = function(first_name,last_name) {
 this.first_name = first_name; // own property
 this.last_name = last_name; // own property
 };
 object_1.prototype.place = "bengaluru"; // prototype property
 object_1.prototype.country = "india"; // prototype property
 let variable_1 = new object_1("ashish","ranjan");

 let own_property = [];
 let prototype_property = [];
 for (let property in variable_1) {
 if (variable_1.hasOwnProperty(property)) {
 own_property.push(property);
 } else {
 prototype_property.push(property);
 }
 }
 console.log(`own properties:: ${JSON.stringify(own_property)}`); // own properties:: ["first_name","last_name"]
 console.log(`prototype properties:: ${JSON.stringify(prototype_property)}`); // prototype properties:: ["place","country"]
</pre>

 <hr />
 <hr />
 <h3>constructor property</h3>
 <hr />
 <hr />
 There is a special constructor property located on the object instances.
 The constructor property is a reference to the constructor function that created the instance.
 <script type="text/javascript">
 $(document).ready(function () {
 console.log("\n\nconstructor property");

 let object_1 = function (first_name, last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_1 = new object_1("ashish1", "ranjan1");
 let variable_2 = new object_1("ashish2", "ranjan2");

 console.log(variable_1.constructor === object_1); // true
 console.log(variable_2.constructor === object_1); // true
 });
 </script>
 <pre>
 let object_1 = function(first_name,last_name){
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_1 = new object_1("ashish1","ranjan1");
 let variable_2 = new object_1("ashish2","ranjan2");

 console.log(variable_1.constructor === object_1); // true
 console.log(variable_2.constructor === object_1); // true
</pre>

<hr />
<hr />
<h3>add prototype from new object</h3>
<hr />
<hr />
<script type="text/javascript">
 $(document).ready(function () {
 console.log("add prototype from new object");

 let object_1 = function (first_name, last_name) {
 this.last_name = last_name;
 this.first_name = first_name;
 };

 let variable_1 = new object_1("ashish1", "ranjan1");

 console.log(variable_1, 'variable_1')
 object_1.prototype.place = "bengaluru";
 object_1.prototype.country = "india";
 object_1.prototype.datentime = () => { console.log("today is April 07, 2022"); };
 object_1.prototype.phonenumber = () => { console.log("1234567890"); };

 // console.log(object_1, "object_1")
 let own_property = [];
 let prototype_property = [];
 for (let property in variable_1) {
 console.log(property, 'property')
 if (variable_1.hasOwnProperty(property)) {
 own_property.push(property);
 } else {
 prototype_property.push(property);
 }
 }
 console.log(`own properties:: ${JSON.stringify(own_property)}`); // own properties:: ["last_name","first_name"]
 console.log(`prototype properties:: ${JSON.stringify(prototype_property)}`); // prototype properties:: ["place","country","datentime","phonenumber"]

 object_1.prototype = {
 property_3: "value 3",
 property_4: () => console.log(this.first_name),
 property_5: () => console.log("a2rp: an Ashish Ranjan presentation"),
 };
 let own_property_2 = [];
 let prototype_property_2 = [];
 let variable_2 = new object_1("ashish1", "ranjan1");
 for (let property in variable_2) {
 if (variable_2.hasOwnProperty(property)) {
 own_property_2.push(property);
 } else {
 prototype_property_2.push(property);
 }
 }
 console.log(`own properties:: ${JSON.stringify(own_property_2)}`); // own properties:: ["last_name","first_name"]
 console.log(`prototype properties:: ${JSON.stringify(prototype_property_2)}`); // prototype properties:: ["property_3","property_4","property_5"]
 });
</script>
<pre>
 let object_1 = function (first_name, last_name) {

 // console.log({first_name});
 // console.log({last_name});
 this.last_name = last_name;
 this.first_name = first_name;
 };

 let variable_1 = new object_1("ashish1", "ranjan1");

 console.log(variable_1, 'variable_1')
 object_1.prototype.place = "bengaluru";
 object_1.prototype.country = "india";
 object_1.prototype.datentime = () => { console.log("today is April 07, 2022"); };
 object_1.prototype.phonenumber = () => { console.log("1234567890"); };

 // console.log(object_1, "object_1")
 let own_property = [];
 let prototype_property = [];
 for (let property in variable_1) {
 console.log(property, 'property')
 if (variable_1.hasOwnProperty(property)) {
 own_property.push(property);
 } else {
 prototype_property.push(property);
 }
 }
 console.log(`own properties:: ${JSON.stringify(own_property)}`); // own properties:: ["last_name","first_name"]
 console.log(`prototype properties:: ${JSON.stringify(prototype_property)}`); // prototype properties:: ["place","country","datentime","phonenumber"]

 object_1.prototype = {
 property_3: "value 3",
 property_4: () => console.log(this.first_name),
 property_5: () => console.log("a2rp: an Ashish Ranjan presentation"),
 };
 let own_property_2 = [];
 let prototype_property_2 = [];
 let variable_2 = new object_1("ashish1", "ranjan1");
 for (let property in variable_2) {
 if (variable_2.hasOwnProperty(property)) {
 own_property_2.push(property);
 } else {
 prototype_property_2.push(property);
 }
 }
 console.log(`own properties:: ${JSON.stringify(own_property_2)}`); // own properties:: ["last_name","first_name"]
 console.log(`prototype properties:: ${JSON.stringify(prototype_property_2)}`); // prototype properties:: ["property_3","property_4","property_5"]
</pre>

<hr /><hr />
<h3>set constructor property when changing the prototype</h3>
There is one crucial side effect of manually setting the prototype to a new object. 
It erases the constructor property! 
This property can be used to check which constructor function created the instance, but since the property has been overwritten, it now gives false results:
<script type="text/javascript">
$(document).ready(function(){
 console.log("constructor overwriting");

 let object_1 = function(first_name,last_name) {
 this.first_name = first_name, // own property
 this.last_name = last_name // own property
 };
 let variable_1 = new object_1("ashish1","ranjan1");
 console.log(`variable_1.constructor === object_1:: ${variable_1.constructor === object_1}`); // variable_1.constructor === object_1:: true
 console.log(`variable_1.constructor === Object:: ${variable_1.constructor === Object}`); // variable_1.constructor === Object:: false
 console.log(`variable_1 instanceof object_1:: ${variable_1 instanceof object_1}`); // variable_1 instanceof object_1:: true

 object_1.prototype.place = "bengaluru"; // prototype property

 // prototype property:: all properties in one
 object_1.prototype = {
 constructor: object_1,
 property_1: "value 1",
 property_2: () => console.log("value 2"),
 property_3: () => console.log("value 3"),
 };

 let variable_2 = new object_1("ashish2","ranjan2");

 let own_property_array = [];
 let prototype_property_array = [];
 for (let property in variable_2) {
 if (variable_2.hasOwnProperty(property)) {
 own_property_array.push(property);
 } else {
 prototype_property_array.push(property);
 }
 }
 console.log(`own properties:: ${JSON.stringify(own_property_array)}`); // own properties:: ["first_name","last_name"]
 console.log(`prototype properties:: ${JSON.stringify(prototype_property_array)}`); // prototype properties:: ["constructor","property_1","property_2","property_3"]
 console.log(`the constructor in protype object:: ${variable_2.constructor}`);
 // without constructor in prototype:: the constructor in protype object:: function Object() { [native code] }
 // with constructor in rpototype:: the constructor in protype object:: function(first_name,last_name) {
 // this.first_name = first_name, // own property
 // this.last_name = last_name // own property
 // }
});
</script>
<pre>
 let object_1 = function(first_name,last_name) {
 this.first_name = first_name, // own property
 this.last_name = last_name // own property
 };
 let variable_1 = new object_1("ashish1","ranjan1");
 console.log(`variable_1.constructor === object_1:: ${variable_1.constructor === object_1}`); // variable_1.constructor === object_1:: true
 console.log(`variable_1.constructor === Object:: ${variable_1.constructor === Object}`); // variable_1.constructor === Object:: false
 console.log(`variable_1 instanceof object_1:: ${variable_1 instanceof object_1}`); // variable_1 instanceof object_1:: true

 object_1.prototype.place = "bengaluru"; // prototype property

 // prototype property:: all properties in one
 object_1.prototype = {
 constructor: object_1,
 property_1: "value 1",
 property_2: () => console.log("value 2"),
 property_3: () => console.log("value 3"),
 };

 let variable_2 = new object_1("ashish2","ranjan2");

 let own_property_array = [];
 let prototype_property_array = [];
 for (let property in variable_2) {
 if (variable_2.hasOwnProperty(property)) {
 own_property_array.push(property);
 } else {
 prototype_property_array.push(property);
 }
 }
 console.log(`own properties:: ${JSON.stringify(own_property_array)}`); // own properties:: ["first_name","last_name"]
 console.log(`prototype properties:: ${JSON.stringify(prototype_property_array)}`); // prototype properties:: ["constructor","property_1","property_2","property_3"]
 console.log(`the constructor in protype object:: ${variable_2.constructor}`);
 // without constructor in prototype:: the constructor in protype object:: function Object() { [native code] }
 // with constructor in rpototype:: the constructor in protype object:: function(first_name,last_name) {
 // this.first_name = first_name, // own property
 // this.last_name = last_name // own property
 // }
</pre>

<hr /><hr />
<h3>objects prototype source</h3>
<hr /><hr />
<script type="text/javascript">
$(document).ready(function(){
 console.log("objects prototype source");

 let object_1 = function (first_name) {
 this.first_name = first_name;
 };
 let variable_1 = new object_1("ashish");
 console.log(`object_1.prototype.isPrototypeOf(variable_1): ${object_1.prototype.isPrototypeOf(variable_1)}`); // object_1.prototype.isPrototypeOf(variable_1): true
});
</script>
<pre>
 let object_1 = function (first_name) {
 this.first_name = first_name;
 };
 let variable_1 = new object_1("ashish");
 console.log(`object_1.prototype.isPrototypeOf(variable_1): ${object_1.prototype.isPrototypeOf(variable_1)}`); // object_1.prototype.isPrototypeOf(variable_1): true
</pre>

<hr /><hr />
<h3>prototype chain</h3>
<hr /><hr />
All objects in JavaScript (with a few exceptions) have a prototype. 
Also, an object's prototype itself is an object. 
Because a prototype is an object, a prototype can have its own prototype! 
Object is a supertype for all objects in JavaScript. 
Therefore, any object can use the hasOwnProperty method.
<script type="text/javascript">
$(document).ready(function(){
 console.log("prototype chain");

 let object_1 = function(first_name,last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_1 = new object_1("ashish1","ranjan1");
 console.log(`variable_1.hasOwnProperty("first_name"):: ${variable_1.hasOwnProperty("first_name")}`); // variable_1.hasOwnProperty("first_name"):: true
 console.log(`typeof object_1.prototype:: ${typeof object_1.prototype}`); // typeof object_1.prototype:: object
 console.log(`Object.prototype.isPrototypeOf(Bird.prototype:: ${Object.prototype.isPrototypeOf(object_1.prototype)})`); // Object.prototype.isPrototypeOf(Bird.prototype:: true)
});
</script>
<pre>
 let object_1 = function(first_name,last_name) {
 this.first_name = first_name;
 this.last_name = last_name;
 };
 let variable_1 = new object_1("ashish1","ranjan1");
 console.log(`variable_1.hasOwnProperty("first_name"):: ${variable_1.hasOwnProperty("first_name")}`); // variable_1.hasOwnProperty("first_name"):: true
 console.log(`typeof object_1.prototype:: ${typeof object_1.prototype}`); // typeof object_1.prototype:: object
 console.log(`Object.prototype.isPrototypeOf(Bird.prototype:: ${Object.prototype.isPrototypeOf(object_1.prototype)})`); // Object.prototype.isPrototypeOf(Bird.prototype:: true)
</pre>

<hr /><hr />
<h3>DRY (Dont Repeat Yourself)</h3>
<hr /><hr />
<script type="text/javascript">
$(document).ready(function(){
 function Cat(name) {
 this.name = name;
 }

 Cat.prototype = {
 constructor: Cat,
 };

 function Bear(name) {
 this.name = name;
 }

 Bear.prototype = {
 constructor: Bear,
 };

 function Animal() { }

 Animal.prototype = {
 constructor: Animal,
 eat: function() {
 console.log("nom nom nom");
 }
 };
});
</script>
<pre>
 function Cat(name) {
 this.name = name;
 }

 Cat.prototype = {
 constructor: Cat,
 };

 function Bear(name) {
 this.name = name;
 }

 Bear.prototype = {
 constructor: Bear,
 };

 function Animal() { }

 Animal.prototype = {
 constructor: Animal,
 eat: function() {
 console.log("nom nom nom");
 }
 };
</pre>

<hr /><hr />
<h3>Object.create</h3>
<hr /><hr />
<script type="text/javascript">
$(document).ready(function (){
 console.log("\n\nObject.create");

 function Animal() { }
 Animal.prototype = {
 constructor: Animal,
 eat: function() {
 // console.log("nom nom nom");
 return "nom nom nom";
 }
 };

 let duck = Object.create(Animal.prototype);
 console.log(`duck eat:: ${duck.eat()}`); // duck eat:: nom nom nom
 let beagle = Object.create(Animal.prototype);
 console.log(`beagle eat:: ${beagle.eat()}`); // beagle eat:: nom nom nom
});
</script>
<pre>
 function Animal() { }
 Animal.prototype = {
 constructor: Animal,
 eat: function() {
 // console.log("nom nom nom");
 return "nom nom nom";
 }
 };

 let duck = Object.create(Animal.prototype);
 console.log(`duck eat:: ${duck.eat()}`); // duck eat:: nom nom nom
 let beagle = Object.create(Animal.prototype);
 console.log(`beagle eat:: ${beagle.eat()}`); // beagle eat:: nom nom nom
</pre>

<hr /><hr />
<h3>Child's Prototype to an Instance of the Parent</h3>
<hr /><hr />
<script type="text/javascript">
$(document).ready(function(){
 function Animal() { }

 Animal.prototype = {
 constructor: Animal,
 eat: function() {
 console.log("nom nom nom");
 }
 };
 function Dog() { }
 
 let beagle = new Dog();
 let animal_instance = new Animal();
 Dog.prototype = Object.create(Animal.prototype);
 console.log(`${(new Dog).eat()}`);
});
</script>
<pre>
 Animal.prototype = {
 constructor: Animal,
 eat: function() {
 console.log("nom nom nom");
 }
 };
 function Dog() { }
 
 let beagle = new Dog();
 let animal_instance = new Animal();
 Dog.prototype = Object.create(Animal.prototype);
 console.log(`${(new Dog).eat()}`);
</pre>

<hr /><hr />
<h3>Reset an Inherited Constructor Property</h3>
<hr /><hr />
<script type="text/javascript">
$(document).ready(function(){
 function Animal() { }
 function Bird() { }
 function Dog() { }

 Bird.prototype = Object.create(Animal.prototype);
 Dog.prototype = Object.create(Animal.prototype);

 // Only change code below this line
 Bird.prototype.constructor = Bird;
 Dog.prototype.constructor = Dog;

 let duck = new Bird();
 let beagle = new Dog();
});
</script>
<pre>
 function Animal() { }
 function Bird() { }
 function Dog() { }

 Bird.prototype = Object.create(Animal.prototype);
 Dog.prototype = Object.create(Animal.prototype);

 // Only change code below this line
 Bird.prototype.constructor = Bird;
 Dog.prototype.constructor = Dog;

 let duck = new Bird();
 let beagle = new Dog();
</pre>

</div>