define a function in "if(){}"

RESOLVED INVALID

Status

()

RESOLVED INVALID
7 years ago
7 years ago

People

(Reporter: zhengzongyi, Unassigned)

Tracking

10 Branch
x86
Windows 7
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

7 years ago
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

Updated

7 years ago
Assignee: nobody → general
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
QA Contact: untriaged → general

Comment 1

7 years ago
"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
Last Resolved: 7 years ago
Resolution: --- → INVALID

Comment 2

7 years ago
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.