Page 160 - CITS - CSA - TP (Volume 1) - Hindi
P. 160

कंप्यूटर सॉफ्टवेयर एप्लीकेशन- CITS




           3   ो ाम को .html फ़ाइल के   प म  सेव कर
           4  वेब  ाउज़र से html फ़ाइल ओपन कर

           5   ाउज़र कं सोल टैब पर जाएँ  और आउटपुट की पुि  कर ।
















           II  कं    र फ़ं  न का उपयोग करना (Using Constructor Functions)

              1  टे  एिडटर ओपन कर
              2  िन िल खत कोड िलख
                 <html >

                 <head>
                 <title> Constructor Functions </title>
                 </head>

                 <body>
                 <script>
                 // Constructor function for creating person objects

                 function Person(firstName, lastName, age) {
                 this.firstName = firstName;

                 this.lastName = lastName;
                 this.age = age;
                 this.fullName = function() {
                 return this.firstName + “ “ + this.lastName;

                 };
                 }
                 // Creating a new instance of Person

                 var person1 = new Person(“John”, “Doe”, 30);
                 // Accessing object properties and methods
                 console.log(person1.firstName); // Output: John
                 console.log(person1.lastName); // Output: Doe
                 console.log(person1.age); // Output: 30

                 console.log(person1.fullName()); // Output: John Doe
                 </script>
                 </body>
                 </html>


                                                           144

                                      CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 40
   155   156   157   158   159   160   161   162   163   164   165