ax1 / iridiumjs

🚀 Boost HTML horsepower
MIT License
1 stars 0 forks source link

Firefox error when IIFE in loaded page #6

Closed ax1 closed 7 years ago

ax1 commented 7 years ago

How to reproduce the error:

Tested with jquery3 and jquery2 same error, tested with or without semicolons, same error

If function is not wrapped in a () the code works well.

This is a minor bug since most functions in dynamic pages are created inside `ir' object but IIFE should be supported since a lot of people use it for encapsulation.

A workaround is to add these js functions in a separate js file.

ax1 commented 7 years ago

The problem was with pseudo-IIFE expressions. If pure IIFE there is no problem with jquery.

Solved, all the code in a IIFE should be covered by a function

Then, this is OK:

(function (){
    function uu(){...}
    document.getElementById('button1').addEventListener('click',uu)
})()

And this is a valid JS script but not parseable by jquery when written in dynamic page

(
    function uu(){...}
    document.getElementById('button1').addEventListener('click',uu)
)()