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

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:

主站蜘蛛池模板: 贵南县| 上饶市| 汽车| 稷山县| 铁岭县| 秀山| 阆中市| 卫辉市| 吉林省| 六盘水市| 襄城县| 西和县| 外汇| 庐江县| 平谷区| 大渡口区| 临海市| 环江| 南投市| 遂昌县| 江山市| 鄂托克前旗| 武乡县| 华阴市| 德江县| 阳山县| 长治市| 沅陵县| 临夏县| 郧西县| 新民市| 平潭县| 邯郸县| 定州市| 汝阳县| 鄱阳县| 松桃| 新津县| 天气| 秦皇岛市| 山东|