tariqinfo304 / Js-Lecture-2

Object Description Detail In JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This documentation provides an overview and explanation of the JavaScript code provided in the README.md file. The code demonstrates various concepts related to object creation, manipulation, and inheritance.

Table of Contents

  • Object Definition
  • Dynamic Property Assignment
  • Getter and Setter
  • Prototype Inheritance
  • Function Definitions

Object Definition

In this section of the code, an object named test is defined using object literal notation. It contains properties such as name, phoneNumber, and address. It also has a getter and setter for the name property. Additionally, properties are dynamically added to the object using bracket notation and dot notation.

Dynamic Property Assignment

The code demonstrates how to dynamically add properties to an object. It uses the variables compnayNameField and compnayNameValue to create a new property named CompanyName with the value "xyz.com".

Getter and Setter

The test object includes a getter and setter for the name property. The getter retrieves the value of the name property, while the setter allows the name property to be updated.

Prototype Inheritance

The code illustrates prototype-based inheritance by defining a constructor function Person. Two instances of the Person class, p1 and p2, are created with different properties. The showName function is added to the prototype of the Person class, enabling both instances to access and call the same function.

Function Definitions

The showName function is defined for both the test object and the Person class. It returns the name property of the respective object.

Note: Please note that some parts of the code are commented out. If you wish to explore those sections, uncomment the relevant lines and execute the code.

About

Object Description Detail In JS


Languages

Language:JavaScript 100.0%