Last Updated: February 25, 2016
·
441
· customcommander

Object.prototype.toString.call() and PhantomJS

When I first came across that technique, I thought it was cool, smart and unbreakable.

Of course the first thing I did was to abuse it:

function isUndefined(arg) {
    return Object.prototype.toString.call(arg) === '[object Undefined]';
}

There is no way I could screw this up right? But then I ran my unit tests with PhantomJS because you know... continuous integration and all that sort of things.

The truth was quite hard to swallow: [object DOMWindow].

In your DOM face!

There are some good explanations out there but I could also simply have done this:

arg === undefined