Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IIFE in classlist_polyfills.js #352

Open
Aditya-Basak opened this issue Jun 25, 2015 · 3 comments
Open

IIFE in classlist_polyfills.js #352

Aditya-Basak opened this issue Jun 25, 2015 · 3 comments

Comments

@Aditya-Basak
Copy link

Sir, my question would be as to why we used IIFE in classlist_polyfills.js whereas it has not been used in the other polyfills classes? As in, what exactly is special about this polyfills that separates it from the other polyfills?
The second part of the question would be, how is it actually testing the existence of the functionality which is the first step in polyfills writing?
Although it might not exactly be an issue, I would be eagerly waiting for a clarification.

@sigod
Copy link
Collaborator

sigod commented Jun 25, 2015

why we used IIFE in classlist_polyfills.js whereas it has not been used in the other polyfills classes?

Wikipedia explains it:
https://en.wikipedia.org/wiki/Immediately-invoked_function_expression#Examples

@Aditya-Basak
Copy link
Author

Okay so going through what you suggested I guess other polyfills would be invoked as and when it's required according to the functionality and execution of the game. We don't want them to be executed pre-maturely. But classlist_polyfills.js interacts with the HTML and CSS required for the game's appearance which anyway needs to be loaded at the very beginning of the game every time the index.HTML page is opened in a browser. So making them an IIFE is justified.
Thanks for your response. It helped a lot in my understanding.
I hope I am not much mistaken, but if so, please correct me.

@sigod
Copy link
Collaborator

sigod commented Jun 25, 2015

so going through what you suggested I guess other polyfills would be invoked as and when it's required according to the functionality and execution of the game. We don't want them to be executed pre-maturely.

No. Read here about polyfills: https://en.wikipedia.org/wiki/Polyfill

But classlist_polyfills.js interacts with the HTML and CSS required for the game's appearance which anyway needs to be loaded at the very beginning of the game every time the index.HTML page is opened in a browser. So making them an IIFE is justified.

Main use for IIFE is to declare a scope. classlist_polyfill has few functions and some variables that mustn't be exposed outside of it. If classlist_polyfill haven't used enclosing function defineElementGetter, DOMTokenList and other variables would've been exposed and possibly modified by other code. Which would lead to undefined behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants