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

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:

主站蜘蛛池模板: 安义县| 阜城县| 县级市| 阿城市| 延津县| 图们市| 乐清市| 阜平县| 玉龙| 丽江市| 桦川县| 柏乡县| 南溪县| 镇江市| 柳江县| 广平县| 曲松县| 安泽县| 上思县| 红原县| 晋城| 百色市| 玉屏| 辉县市| 永平县| 广水市| 彭山县| 乌鲁木齐市| 临沭县| 汉阴县| 容城县| 镇宁| 南涧| 应用必备| 辽源市| 通榆县| 西安市| 昭通市| 新兴县| 隆回县| 台中市|