4 ms·
Super optimized as in the sense that this line was distilled to be as small and lightweight as you can get it while making sure it works with actual tests. Jus
by Raphmedia 7y ago
Super optimized as in the sense that this line was distilled to be as small and lightweight as you can get it while making sure it works with actual tests.
Just search for "Javascript check if variable is window" to find all kinds of solutions that seem to work at first glance but would probably end up breaking under some specific situations. Some people tests against the .toString of the variable, others look to see if the variable has under it what 'window' usually contains while some create a new instance of 'window' and compare it to their variable, etc.
The solution that "is-window" brings seems to be as perfect as you are going to get it. In an ecosystem where things change quickly and you are not sure where your code is running it's easy to become dependent to such crutches. You do not want the mental burden of remembering all the hacks.
I am not defending this particular package and I'm sure we could come with a better solution of testing it. If you do, make a pull request. I am merely explaining why those package happen.