प्रोटोटाइप इनहेरिटेंस
JavaScript में ऑब्जेक्ट्स अपने प्रोटोटाइप से प्रॉपर्टीज़ और मेथड्स इनहेरिट करते हैं। हम आमतौर पर new Object() के साथ एक बनाते हैं, जो Object.prototype से भी इनहेरिट करता है। उसी तरह, new Date() के साथ ऑब्जेक्ट्स Date.prototype इनहेरिट करते हैं।
उदाहरण
<!DOCTYPE html> <html>
<body>
<h2>Department Details</h2>
<p id="details"></p>
<script>
function Department(myid, name, section) {
this.id = myid;
this.name = name;
this.section = section;
}
var myDept = new Department("AKD", "Marketing", "North");
document.getElementById("details").innerHTML =
"The name and section of the Department is " + myDept.name + " and "
+ myDept.section+ " respectively.";
</script>
</body>
</html>