- JavaScript and JSON Essentials
- Sai Srinivas Sriparasa
- 218字
- 2021-07-23 15:52:43
Objects
Objects are another way of handling data. In arrays the indexes are commonly numerical; objects give us a robust way of assigning and retrieving data. Objects are derived from the object-oriented programming concept; a programming paradigm that is very popular. Objects are a virtual representation of real-time data; they allow us to organize our data into logical groups via properties and methods. Properties describe the state of the object, while methods describe the behavior of the object. Properties are a key-value pair that holds the information. Take a look at the following:

In the previous example, we have instantiated a person
object, and then added the firstname
and lastname
properties that described the object. We added behavior to the object by creating a method called getFullName
, the method accessed the object properties, retrieved the data, and alerted the output onto the screen. In this example the properties are accessed by the dot notation; we could also access a property by putting the property name in square brackets similar to an array, but it is not popular. This is shown as follows:

The second way of creating an object is by using the curly braces. Here we are introduced to the this
keyword, which provides a reference to the object's properties and methods, as shown in the following:

- PHP程序設計(慕課版)
- Java高手真經(高級編程卷):Java Web高級開發技術
- Visual C++數字圖像模式識別技術詳解
- VSTO開發入門教程
- 鋒利的SQL(第2版)
- Nginx Essentials
- QTP自動化測試進階
- 領域驅動設計:軟件核心復雜性應對之道(修訂版)
- 零基礎Java學習筆記
- Red Hat Enterprise Linux Troubleshooting Guide
- Python網絡爬蟲技術與應用
- CodeIgniter Web Application Blueprints
- PHP 8從入門到精通(視頻教學版)
- 深度實踐KVM:核心技術、管理運維、性能優化與項目實施
- Learning Concurrency in Python