1
Vote

Incorrect assert in typeof.js

description

In typeof.js, there are two asserts that look like this:

var opts = Object.prototype.toString;
assert('[object Global]',opts.call(undefined));
assert('[object Global]',opts());

The first assert has the comment "call on the undefined should pass global, this is used by some ajax libraries", but is this still valid? Which ajax libraries use this, and do they still use it?

When you run it in Firefox, Chrome and IE9, it outputs "[object Undefined]" and not "[object Window]", even when you're not in strict mode.

The second call to opts() gives you "[object Undefined]" in Firefox and Chrome, but "[object Window]" in IE, so that seems a bit more vague.

comments

cin wrote May 3, 2012 at 3:25 PM

I can agree about the first assert, but the second gives you in Chromium Version 20.0.1094.0 (svn131123):
var opts = Object.prototype.toString
undefined
opts()
"[object global]"
dojo uses such technique to define dojo.global