3 ms·
To the author, here's a common pattern you can use to avoid defining global variables unless it's needed. ;(function() { const dropzoneDefaults = { ... }
by lioeters 3y ago
To the author, here's a common pattern you can use to avoid defining global variables unless it's needed.
;(function() {
const dropzoneDefaults = { ... }
class EasyDropzone { ... }
const h = function() { ... }
// Export to global
window.EasyDropzone = EasyDropzone
})()
- pazvanti 3y agoThanks. Will definitely try to improve the code. JavaScript is not my main language and I still have many tricks that I should learn.
- lioeters 3y agoHere is some information about this pattern, it's called Immediately Invoked Function Expression. It's a way to create a function scope so that all variables are local, except for any that you want to "export" as a global. https://developer.mozilla.org/en-US/docs/Glossary/IIFE https://developer.mozilla.org/en-US/docs/Glossary/IIFE