Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8297

Re: defining functions

From "J.R." <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: defining functions
Date 2011-11-13 21:39 -0200
Organization Aioe.org NNTP Server
Message-ID <j9pkf6$3b5$1@speranza.aioe.org> (permalink)
References <4eb4a8de$0$28686$a8266bb1@newsreader.readnews.com> <j9499f$opc$1@speranza.aioe.org> <2999732.SPkdTlGXAF@PointedEars.de>

Show all headers | View raw


On 07/11/2011 10:26, Thomas 'PointedEars' Lahn wrote:

>> *And finally, the most important difference IMO lies in the hoisting
>                                                                ^^^^^^^^
>> behavior*:
>    ^^^^^^^^
> I beg your pardon?
>
>> [...] all variables, no matter where in the function body they are
>> declared, get hoisted to the top of the function behind the scenes.
>
> Utter nonsense.

No, it is not.

>> The same applies for functions because they are just objects assigned to
>> variables.
>
> That is oversimplifying talk; nothing is "hoisted" here.  What really
> happens is that all declarations in source code are specified to happen
> before control reaches the first statement of the execution context.
> Variable instantiation adds a property to the ES 1 to 3 Variable Object,
> with the identifier of the variable or function as name [1].  In ES 5.x,
> this is described as Declaration Binding Instantiation, i. e. bindings added
> to a VariableEnvironment's Environment Record, instead, but it follows
> essentially the same pattern [2].

The book's author explains the term "hoisting" on page 15:

"[...] For completeness, let’s mention that actually at the 
implementation level things are a little more complex. There are two 
stages of the code handling, where variables, function declarations, and 
formal parameters are created at the first stage, which is the stage of 
parsing and entering the context. In the second stage, the stage of 
runtime code execution, function expressions and unqualified identifiers 
(undeclared variables) are created. But for practical purposes, we can 
adopt the concept of hoisting, which is actually not defined by 
ECMAScript standard but is commonly used to describe the behavior."

If you google for "variable hoisting +javascript", you'll see that the 
term has been used by some renowned JS developers (Kangax, Nicholas 
Zakas, Stoyan Stefanov, Dustin Diaz, Dmitry Soshnikov, etc.) as a 
simplification of the ECMAScript Language Specification.


>> I'd strongly suggest that you purchase and read this book carefully.
>
> I strongly suggest that you stop believing blindly in what book authors
> (anyone, really) say and start thinking for yourself.  /Sapere aude!/
>

I stand my point: this is an excellent book, although there are some 
minor errors / typos in it the same way it happens to other excellent / 
good books. And praising a book / author has nothing to do with blind faith.

-- 
Joao Rodrigues (J.R.)

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

defining functions Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-05 03:09 +0000
  Re: defining functions "Richard Cornford" <Richard@litotes.demon.co.uk> - 2011-11-05 04:35 +0000
    Re: defining functions Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-05 14:46 +0100
  Re: defining functions "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-05 19:19 -0200
    Re: defining functions Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-07 13:26 +0100
      Re: defining functions "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-13 21:39 -0200
        Re: defining functions Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 19:49 +0100
          Re: defining functions "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 17:00 -0200

csiph-web