Timeline for Toggling the background color of a page using JavaScript closures
Current License: CC BY-SA 4.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 22, 2019 at 17:25 | comment | added | Dov Rine | I think you're probably better off coming up with a less trivial example to practice the module pattern on. Something like a todo list or a table with add/delete row functionality. | |
Jul 22, 2019 at 17:24 | comment | added | Dov Rine |
@Anthony: There's really not too much to do as an IIFE here b/c you can just attach the first buttons handler through onclick in the DOM. If you do that, then try to put your js in an external file and use the IIFE to create a namespace for it, sort of like how jQuery does it.
|
|
Jul 22, 2019 at 16:26 | comment | added | Anthony | Thank you for taking the time to write this out, this is exactly the sort of feedback I was looking for. I like that you got rid of the weird flag variable, and I like that everything is still contained within functions to keep the global namespace clean. It's readable and much more terse. This is the sort of code I'm looking to write! Would you recommend enclosing these functions inside an IIFE as in my first attempt? I am/was attempting to learn the "module" pattern as it pertains to using closure effectively and so I'm curious about whether that is a good approach or not. Thanks again! | |
Jul 22, 2019 at 10:01 | comment | added | Simon Forsberg | Welcome to Code Review, thanks for improving your answer as requested! | |
Jul 22, 2019 at 9:18 | history | edited | Dov Rine | CC BY-SA 4.0 |
Added additional explanation
|
Jul 22, 2019 at 8:25 | review | Low quality posts | |||
Jul 22, 2019 at 9:55 | |||||
Jul 22, 2019 at 6:20 | history | edited | Dov Rine | CC BY-SA 4.0 |
Added activateColorButton function expression
|
Jul 22, 2019 at 6:10 | review | First posts | |||
Jul 22, 2019 at 8:21 | |||||
Jul 22, 2019 at 6:07 | history | answered | Dov Rine | CC BY-SA 4.0 |