Page 145 - CITS - Computer Software Application -TT
P. 145

COMPUTER SOFTWARE APPLICATION - CITS



                 return this.firstName + “ “ + this.lastName;
                 };

                 var person1 = new Person(“Alice”, “Smith”);
           4  Encapsulation:
              •  Encapsulation can be achieved through closures and private variables within functions.
                 function Counter() {
                  var count = 0;

                 this.increment = function() {
                   count++;
                  };
                  this.getCount = function() {

                   return count;
                  };
                 }
              var counter = new Counter();
              counter.increment();
              console.log(counter.getCount()); // Outputs: 1
           5  Polymorphism:
              •  JavaScript supports polymorphism through dynamic typing, allowing objects to be used in multiple contexts
                 without explicit type definitions.
                 function displayInfo(obj) {
                  console.log(obj.getDetails());
                 }
                 var student = {
                  name: “Bob”,
                  getDetails: function() {
                   return “Student: “ + this.name;
                  }
                 };

              displayInfo(student); // Outputs: Student: Bob
           In summary, JavaScript’s object-oriented development is centered around objects, prototypes, and constructor
           functions. It offers a flexible and dynamic approach to building and extending objects, making it well-suited for
           web development where dynamic and responsive behaviors are essential.

             Document Object Model


           The document object represents the whole html document.
           When html document is loaded in the browser, it becomes a document object. It is the root element that represents
           the html document. It has properties and methods. By the help of document object, we can add dynamic content
           to our web page.
           As mentioned earlier, it is the object of window. So
           window.document

           Is same as


                                                           132

                             CITS : IT&ITES - Computer  Software Application - Lesson 37 - 46
   140   141   142   143   144   145   146   147   148   149   150