On 2/7/11, Asen Bozhilov <asen.bozhi...@gmail.com> wrote: > Dmitry A. Soshnikov : > >> http://dmitrysoshnikov.com/notes/note-4-two-words-about-hoisting/ > > Excellent article. > > The most interesting example for me was: > > // a.js > > function foo() { > alert(1); > } > > foo(); // 2 ? > > // b.js > > function foo() { > alert(2); > } > > Which demonstrates how Function Declarations are created during > variable instantiation time on entering in particular execution > context. And especially how the second declaration replace the value > of created property of variable object or lexical environment. > > However, sometimes if you know how it works FD you can be confused > from non-standard Function Statements. > > e.g. > > foo(); //It will alert 1 > > function foo() { > alert(1); > } > > if (true) { > function foo() { > alert(2); > } > } > > foo(); //2 > > While the first is FD and will be hoisted the second is non standard > FunctionStatement and will be created during execution time and will > replace the value of `foo' with newly created function. > > And of course here is some quirks behavior and some implementation > interpret FS as FD, but this is out of my example. > In some browsers it will be hoisted regardless of the `if` Statement.``
> For those who are interested in this topic, Jury has written great article: > > <URL: http://kangax.github.com/nfe/> Yeah. -- Garrett -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com