- 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:

- INSTANT Mock Testing with PowerMock
- 計算機網絡
- 嵌入式軟件系統測試:基于形式化方法的自動化測試解決方案
- INSTANT OpenCV Starter
- 摩登創客:與智能手機和平板電腦共舞
- Magento 2 Development Cookbook
- Web Application Development with MEAN
- Visual Basic程序設計習題解答與上機指導
- QTP自動化測試進階
- Oracle 18c 必須掌握的新特性:管理與實戰
- Spring MVC+MyBatis開發從入門到項目實踐(超值版)
- Android傳感器開發與智能設備案例實戰
- Buildbox 2.x Game Development
- JavaScript程序設計:基礎·PHP·XML
- PhoneGap 4 Mobile Application Development Cookbook