JavaScript: Difference between revisions

Content deleted Content added
m Reverted edits by 68.184.1.177 (talk) to last version by Mindmatrix
Line 92:
 
=== Functional ===
; first-class functions: [[Subroutine|Functions]] are [[first-class function|first-class]]; they are objects themselves. As such, they have properties and methods, such as <code>length</code> and <code>call()</code>;{{Sfn |Flanagan|2006| pp=137–139}} and they can be assigned to variables, passed as arguments, <code>return</code>-edreturned by other functions, and manipulated like any other object.{{Sfn |Flanagan|2006| p=134}} Any reference to a function allows it to be invoked using the <code>()</code> operator.{{Sfn |Flanagan|2006| p=81}}
; nested functions: "Inner" or "nested" functions are functions defined within another function. They are created each time the outer function is invoked. In addition to that, the [[Scope (programming)|scope]] of the outer function, including any constants, local variables and argument values, become part of the internal state of each inner function object, even after execution of the outer function concludes.{{Sfn |Flanagan|2006| p=141}}
; closures: JavaScript allows nested functions to be created, with the [[lexical scope]] in force at their definition, and has a <code>()</code> operator to invoke them now or later. This combination of code that can be executed outside the scope in which it is defined, with its own scope to use during that execution, is called a [[Closure (computer science)|closure]] in computer science.{{Sfn |Flanagan|2006| p=144}}