How many globals make sense to be passed to the IIFE wrapper?

后端 未结 3 440
我寻月下人不归
我寻月下人不归 2021-01-22 12:39

To which extent does it make sense to pass plenty of global values to an IIFE?

The common thing is just to pass 3 as far as I see everywhere (window, document and undefi

3条回答
  •  执念已碎
    2021-01-22 12:54

    would it make sense to pass more if they are used more than 10 times in the code just for the fact of minification?

    If you care that much about minification, sure, why not?

    The common thing is just to pass 3 as far as I see everywhere (window, document and undefined)

    Yes, altough you see not passing document, or passing jQuery (aliased as $), just as often. And of course it's not only about minification, but about performance, and you only care for window and document on that behalf.

    it would always make sense to pass as many global variables as possible, right?

    Well, except you don't use them in your code. Symbol, Object, Error, Date, JSON, Math and the others are not needed that often in most code. And developers don't like to do those byte counts you are suggesting every time they change a bit of code, so this IEFE boilerplate just stays as it is (and imho there's much cargo cult to it).

    You would let your minifier do this automatically if you'd really care.

提交回复
热议问题