JS's way of scoping variables is significantly different to Perl, because of the hoisting of variable declarations in JS, i.e. the scope is the whole surrounding function from start to end, i.e. even prior to var !!!
As a consequence there is no block scope like in Perl
A usual work around for block scopes is to use a "throw away" anonymous function and to call it right away.
This doesn't seem to make sense here, because we don't see any potential conflict or even var declarations (see my first statement)
As a side note: there are plans to introduce a let command which works almost the same like my in Perl.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery
In reply to Re: OT: Converting some JS to Perl (Hoisting)
by LanX
in thread OT: Converting some js to Perl
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |