एरो फंक्शन में "this" कीवर्ड
जावास्क्रिप्ट का 'this' कीवर्ड उस ऑब्जेक्ट को संदर्भित करता है जिससे यह संबंधित होता है। एरो फंक्शन में, 'this' एक ग्लोबल ऑब्जेक्ट से संबंधित होता है। एक साधारण फंक्शन में, 'this' कीवर्ड undefined परिणाम दे सकता है, लेकिन एरो फंक्शन में यह एक सटीक मान देता है।
उदाहरण
<html> <body> <script> function Student(fname, grade) { this.fname = fname; this.grade = grade; this.details = function() { return () => { document.write(`Hi, I'm ${this.fname} from ${this.grade} grade`); }; } } let info = new Student('picaso', 'seventh'); let printInfo = info.details(); printInfo(); </script> </body> </html>
आउटपुट
Hi, I'm picaso from seventh grade