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

জাভাস্ক্রিপ্ট কনস্ট্রাক্টরে প্রপার্টি এবং মেথড যোগ করার পদ্ধতি


জাভাস্ক্রিপ্ট কনস্ট্রাক্টরে প্রপার্টি এবং মেথড যোগ করার কোড নিচে দেওয়া হলো −

উদাহরণ

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style>    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       } </style> </head> <body> <h1>Add property,method to javaScript constructor</h1> <div style="color: green;" class="result"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to add property, method to constructor</h3> <script>    let resEle = document.querySelector(".result");    function Human(firstName,lastName){       this.firstName = firstName;       this.lastName = lastName;    }      let obj = new Human('Rohan','Sharma');    document.querySelector(".Btn").addEventListener("click", () => {       Human.prototype.welcome = function(){          return 'Welcome '+this.firstName + ' ' + this.lastName;       }       Human.prototype.age = 22;       resEle.innerHTML = 'Adding property to constructor : age <br>' + obj.age + '<br>';       resEle.innerHTML += 'Adding function to constructor : welcome() <br>' +       obj.welcome() + '<br>';    }); </script> </body> </html>

আউটপুট

উপরোক্ত কোড নিম্নলিখিত আউটপুট তৈরি করবে −

জাভাস্ক্রিপ্ট কনস্ট্রাক্টরে প্রপার্টি এবং মেথড যোগ করার পদ্ধতি

'CLICK HERE' বাটনে ক্লিক করলে −

জাভাস্ক্রিপ্ট কনস্ট্রাক্টরে প্রপার্টি এবং মেথড যোগ করার পদ্ধতি

  1. জাভাস্ক্রিপ্ট বুলিয়ান কনস্ট্রাক্টর প্রপার্টি

  2. জাভাস্ক্রিপ্ট Date constructor প্রপার্টি

  3. জাভাস্ক্রিপ্টে লুপে ডিলে যোগ করা

  4. C#-এ রিড-অনলি প্রপার্টি যোগ করা (Add Read-Only Property)