Closed Bug 730202 Opened 12 years ago Closed 12 years ago

define a function in "if(){}"

Categories

(Core :: JavaScript Engine, defect)

10 Branch
x86
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: zhengzongyi, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
Build ID: 20120215223356

Steps to reproduce:

if(true){
    alert(typeof fn);
    function fn(){}
}


Actual results:

alert "undefined"


Expected results:

alert function
Assignee: nobody → general
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
QA Contact: untriaged → general
"Several widely used implementations of ECMAScript are known to support the use of FunctionDeclaration as a Statement. [...] It is recommended that ECMAScript implementations either disallow this usage of FunctionDeclaration or issue a warning when such a usage is encountered."[1]

[1] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
to clarify the following is completely valid. But function declaration is parsed before the code runs so it would not be able to check the variables.

if(true) {
    var fn = function() {};
    alert(typeof fn);
}
You need to log in before you can comment on or make changes to this bug.