- From: Adam Barth <w3c@adambarth.com>
- Date: Wed, 8 Aug 2012 17:23:21 -0700
- 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 UTC