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
Written by Julien Gonzalez
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#