super
super कीवर्ड का उपयोग किसी ऑब्जेक्ट के पेरेंट पर फंक्शन्स को एक्सेस और कॉल करने के लिए किया जाता है। super.prop और super[expr] एक्सप्रेशन्स क्लासेस और ऑब्जेक्ट लिटरल्स दोनों में किसी भी मेथड परिभाषा में मान्य हैं। इसका उपयोग "extended" क्लास में किया जाता है, जो "extends" कीवर्ड का उपयोग करती है।
सिंटैक्स
super(arguments);
उदाहरण
निम्नलिखित उदाहरण में, "Person" नामक क्लास की विशेषताओं को "Student" नामक दूसरी क्लास में बढ़ाया गया है। दोनों क्लासेस में हमने अद्वितीय प्रॉपर्टीज का उपयोग किया है। यहां "super" कीवर्ड का उपयोग पेरेंट क्लास (Person) से एक्सटेंडेड क्लास (Student) में प्रॉपर्टी एक्सेस करने के लिए किया गया है, जबकि "this" कीवर्ड का उपयोग एक्सटेंडेड क्लास की अपनी प्रॉपर्टी एक्सेस करने के लिए किया गया है।
<html> <body> <script> class Person { constructor(name, grade) { this.name = name; this.grade = grade; } goal() { return `${this.name} wants to become a crickter!`; } interest() { return `${this.name} interested in cricket !`; } } class Student extends Person { constructor(name, grade) { super(name, grade); } need() { return `${this.name} needs a cricket kit`; } career() { return `${super.interest()} ${super.goal()} ${this.need()}`; } } const student = new Student('Rishab pant', '7'); document.write(student.career()); </script> </body> </html>
आउटपुट
Rishab pant interested in cricket ! Rishab pant wants to become a crickter! Rishab pant needs a cricket kit