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

Chapter 2. Functions, Closures, and Modules

In the previous chapter, we deliberately did not discuss certain aspects of JavaScript. These are some of the features of the language that give JavaScript its power and elegance. If you are an intermediate- or advanced-level JavaScript programmer, you may be actively using objects and functions. In many cases, however, developers stumble at these fundamental levels and develop a half-baked or sometimes wrong understanding of the core JavaScript constructs. There is generally a very poor understanding of the concept of closures in JavaScript, due to which many programmers cannot use the functional aspects of JavaScript very well. In JavaScript, there is a strong interconnection between objects, functions, and closures. Understanding the strong relationship between these three concepts can vastly improve our JavaScript programming ability, giving us a strong foundation for any type of application development.

Functions are fundamental to JavaScript. Understanding functions in JavaScript is the single most important weapon in your arsenal. The most important fact about functions is that in JavaScript, functions are first-class objects. They are treated like any other JavaScript object. Just like other JavaScript data types, they can be referenced by variables, declared with literals, and even passed as function parameters.

As with any other object in JavaScript, functions have the following capabilities:

  • They can be created via literals
  • They can be assigned to variables, array entries, and properties of other objects
  • They can be passed as arguments to functions
  • They can be returned as values from functions
  • They can possess properties that can be dynamically created and assigned

We will talk about each of these unique abilities of a JavaScript function in this chapter and the rest of the book.

主站蜘蛛池模板: 乐陵市| 徐闻县| 平遥县| 鄢陵县| 嘉鱼县| 西丰县| 晋城| 黔西| 桂阳县| 舞阳县| 青海省| 鹤壁市| 准格尔旗| 乐都县| 巴林右旗| 临高县| 柳河县| 克东县| 噶尔县| 通许县| 尼木县| 固原市| 淄博市| 象州县| 伊川县| 南平市| 内江市| 乌什县| 麟游县| 酉阳| 东海县| 凤凰县| 阿拉善右旗| 高陵县| 武山县| 息烽县| 皮山县| 汕尾市| 尤溪县| 海盐县| 繁昌县|