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 === undefinedWritten by Julien Gonzalez
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#