bellcliff
bellcliff

Reputation: 3

function var in closure cause error on Firefox7/8

code as below:


    function(){
        log1();
        function log1(evt) {
            alert("1");
        }
    }();

on firefox 8, nothing happend, and error log1 is not defined shown in firebug console. The code could be executed succeeded on Chrome and IE9.

Upvotes: 0

Views: 44

Answers (2)

jfriend00
jfriend00

Reputation: 707546

It works fine in Firefox 8.0 like this:

(function (){     
    log1();         
    function log1(evt) {
        alert("1");         
    }     
})();

You can see it work here: http://jsfiddle.net/jfriend00/2QYHJ/

Upvotes: 0

Ryan Yiada
Ryan Yiada

Reputation: 4769

Your function can not be executed. you can make it like this way:

(function(){
    log1();
    function log1(evt) {
        alert("1");
    }
})();

Upvotes: 1

Related Questions