The wrapper object trick
If you’re a Modernizr user, then you’ve probably recognize this kind of object! No…really? ok, then take a look at the following Modernizr tests:
And now you’ve probably understand what I’m talking about, right? What we’re doing is taking advantage of the fact that Boolean is an object and that means we can add properties to it. If you take a look at the Modernizr source code, you’ll notice that it’ll only create an object whenever it knows that the receiving literal Boolean is true. And there’s a reason for that behavior: since new Boolean ends up creating an object, then a Boolean instance will always evaluate to true in any test. Here’s an example of what I mean:
So, we need to change the code so that it behaves correctly. Here’s how you’re supposed to write the previous snippet:
And that’s it for now. Stay tuned for more.