strict mode
fancybox.umd.js should be capable of running in strict mode.
Hi,
Could you, please, explain what do you mean by that? The code is written in ES6, and ES6 modules are always in strict mode by defalt. All *.umd.js files are generated using Rollup and Babel.
If "use strict"; is at the front of the file, it fails.
fancybox.umd.js?1653245295:1 Uncaught TypeError: Cannot set property window of #<Window> which has only a getter
Works fine for me - https://jsfiddle.net/qh3dj2gv/1/
There, in your fiddle, "use strict" is only being applied to your snippet, not to the actual fancy box javascript file. If you don't use CDN and actually add "use strict"; to the top of the physical fancybox.umd.js file, it fails. (v4.0.25-27)
First of all, why would you want to do that? What is your motivation? It's so weird to do that, and you should never touch files directly.
Then, your message Cannot set property window of #<Window> which has only a getter does not makes sense. I believe that it is caused by Fancybox registering self globally, so that it is available everywhere from the page. Global variables in JavaScript are attached to the "global object", which in a browser environment is aliased to window object. So, you are basically asking me to make Fancybox NOT global, but that means - you will not be able to use it at all.
My motivation is to use scripts in my projects that pass my level of scrutiny for how well they are written. The majority of good javascript packages have "use strict"; as the first line of the file. It is a sign that the script has been fully vetted to behave properly ... especially in a mixed script environment. I use many scripts with "use strict"; at the top that have no problem attaching an object to "window".
I have taken the time to examine the script in more detail and it seems the Fancybox object does run in strict mode. It is just the Rollup or Babel generated hoisting of the object that is breaking strict mode requirements. I can work around that for my web browser use case(s).