javascript - Firefox: function hoisting error -


i used assume functions hoisted top of block of javascript code.

for example, works:

document.addeventlistener('something', dummy); function dummy(){     console.log('dummy'); } 

but doesn't work , throws referenceerror in firefox, works in chrome:

if(document){             document.addeventlistener('something', dummy1);     function dummy1(){         console.log('dummy');     } } 

fiddle code

initially, assumed chrome throw error before tested, somehow works correctly. can explain why doesn't work in firefox?

it appears has been issue quite while - here's reference 2011: http://statichtml.com/2011/spidermonkey-function-hoisting.html

apparently firefox happily hoist function declarations outside of block, doesn't inside block. author of linked article argues (while unexpected) compliant ecma-262 spec, allows statements inside of block...as function declaration not statement. however, i'll note firefox happily allows function declarations inside of block - merely refuses hoist them.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -