Interesting ES5 side effect / window.hasOwnProperty(x) !== hasOwnProperty(x)

Wes Garland wes at
Mon Feb 7 10:54:17 PST 2011

I bumped into something this morning that I thought might be worth pointing
out -- mostly because I was surprised to have seemingly-valid ES3 code break
on an ES5 browser without strict mode in play.

One of my developers has a habit of writing tests like

  if (!hasOwnProperty("console"))
    // supply my own console object instead

This works fine on our deployment-target browsers, and up until very
recently, on Firefox 4 betas.   With the latest Firefox Minefield build,
this same code throws a surprising (to me) error: "Error: can't convert
undefined to object".

If I understand the relevant Mozilla bug correctly (and I'm not sure that I
do) -- -- this is
because of the way bindings are looked up in ES5


Comments? Obviously, the work-around is easy -- always invoke
window.hasOwnProperty instead of hasOwnProperty -- but I wonder what other
daemons lurk in the same corners.


Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list