Skip to content

Commit

Permalink
JS-Object Oriented concepts are added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayajahamad committed Sep 27, 2023
1 parent dd9f782 commit 6796aab
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Javascript/05-OOJS/p23.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OOJS</title>
</head>
<body>
<center>
<h1>PROTOTYPE</h1>
<p>Prototype keyword - is used to create a property to an Constructor externally</p>
</center>
<hr>
<script>
function Student(){
// Local Property
let name, gender;

// Constructor Property
this.name = "ABCD";
this.gender = "Male";
}
let stud = new Student(); // Constructor object

document.write("<b>Stud.name : </b>" + stud.name + "<br><br>");
document.write("<b>Stud.gender : </b>" + stud.gender + "<br><br>");

stud.age = 20;
document.write("<b>Stud.age : </b>" + stud.age + "<br><br>");

let stud1 = new Student();
document.write("<b>Stud1.name : </b>" + stud1.name + "<br><br>");
document.write("<b>Stud1.gender : </b>" + stud1.gender + "<br><br>");
document.write("<b>Stud1.age : </b>" + stud1.age + "<br><br>");

Student.prototype.age1 = 30; // Defined a external property using Prototype.

let student1 = new Student();
document.write("<b>student1.age1 : </b>" + student1.age1 + "<br><br>");

let student2 = new Student();
document.write("<b>student2.age1 : </b>" + student2.age1 + "<br><br>");

</script>
</body>
</html>

0 comments on commit 6796aab

Please sign in to comment.