官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 英德市| 北碚区| 福建省| 武平县| 宜良县| 普兰店市| 丹寨县| 莱州市| 桃园县| 西丰县| 栖霞市| 内乡县| 白水县| 伊金霍洛旗| 陵水| 麻城市| 金阳县| 通江县| 永仁县| 龙海市| 清新县| 海丰县| 田阳县| 绵阳市| 沅江市| 营山县| 得荣县| 南木林县| 湖口县| 湛江市| 安平县| 唐海县| 托里县| 江陵县| 泾阳县| 翁源县| 佳木斯市| 裕民县| 凤阳县| 木里| 即墨市|