কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টের অ্যারো ফাংশনে 'this' কীওয়ার্ড কীভাবে অ্যাক্সেস করবেন?

অ্যারো ফাংশনে "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
  1. জাভাস্ক্রিপ্ট this কীওয়ার্ড ব্যাখ্যা

  2. জাভাস্ক্রিপ্টে অবজেক্ট প্রপার্টি অ্যাক্সেস করার পদ্ধতি

  3. জাভাস্ক্রিপ্টে Concise Arrow Functions

  4. ফাংশন-এ ঘোষিত ভেরিয়েবল অন্য ফাংশন থেকে অ্যাক্সেস - JavaScript