1.

Explain how Inheritance works in constructor Functions?

Answer»

Create a custom object in JavaScript, using the “new”. It is followed by the constructor method Object():

var department = new Object();

Let us see an example to create a custom object in JavaScript: 

<html>    <head>       <TITLE>Custom objects</title>       <script>          var department = new Object();          department.name = "Finance";          department.ID  = 005;          department.location = "North";       </script>    </head>    <body>       <H2>Department Details</h2>       <script>          document.write("Department Name = " +  department.name + "<br>");          document.write("Department Id = " + department.id + "<br>");           document.write("Department Location = " + department.location);       </script>    </body> </html>

The output: 

Above, firstly we have created an object:

var department = new Object();

After that properties are ASSIGNED

department.name = "Finance"; department.id  = 005; department.location = "North";


Discussion

No Comment Found