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

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:

主站蜘蛛池模板: 富裕县| 西乌珠穆沁旗| 云浮市| 沈丘县| 太湖县| 健康| 绥宁县| 互助| 奉节县| 大安市| 济阳县| 兴义市| 遵化市| 宜黄县| 吴堡县| 邮箱| 屯留县| 佛冈县| 三江| 新巴尔虎左旗| 忻城县| 包头市| 大冶市| 韩城市| 桑日县| 翁牛特旗| 舟山市| 延庆县| 周口市| 朝阳县| 历史| 宁晋县| 莫力| 门源| 商河县| 乌什县| 双峰县| 宁武县| 茂名市| 徐水县| 镇雄县|