W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2012

Re: [IndexedDB] Problems unprefixing IndexedDB

From: Adam Barth <w3c@adambarth.com>
Date: Wed, 8 Aug 2012 17:23:21 -0700
Message-ID: <CAJE5ia_X56PYdWbwHFX9OASRKbROBAzjM+R4kezeBmFC1LCe2Q@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: Kyle Huey <me@kylehuey.com>, Web Applications Working Group WG <public-webapps@w3.org>
On Wed, Aug 8, 2012 at 5:12 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> On Wed, Aug 8, 2012 at 5:06 PM, Kyle Huey <me@kylehuey.com> wrote:
>> Hello all,
>>
>> Jonas mentioned earlier on this list that we unprefixed IndexedDB in Firefox
>> nightlies some time ago.  We ran into a bit of a problem.[0]  Most of the
>> IndexedDB tutorials (including ours and HTML5 Rocks[1] :-/) tell authors to
>> deal with prefixing with:
>>
>> var indexedDB = window.indexedDB || window.webkitIndexedDB ||
>> window.mozIndexedDB || window.msIndexedDB || ...
>>
>> This code has a bug when executed at global scope.  Because the properties
>> are on the prototype chain of the global object, 'var indexedDB' creates a
>> new property on the global.  Then window.indexedDB finds the new property
>> (which has the value undefined) instead of the IDBFactory on the prototype
>> chain.  The result is that all of the pages that do this no longer work
>> after we unprefix IndexedDB.
>
> Just for reference, the correct way to do this is:
>
> window.indexedDB = window.indexedDB || window.webkitIndexedDB ||
> window.mozIndexedDB || window.msIndexedDB || ...
>
> This avoids the var hoisting that's causing the problems.

If we're telling people to use that pattern, we might as well just not
prefix the API in the first place because that pattern just tells the
web developers to unilaterally unprefix the API themselves.

Adam
Received on Thursday, 9 August 2012 00:24:20 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:54 GMT