- From: Nikunj Mehta <nikunj@o-micron.com>
- Date: Sat, 13 Mar 2010 01:44:31 -0800
- To: Aaron Boodman <aa@google.com>
- Cc: Jeremy Orlow <jorlow@chromium.org>, Kris Zyp <kris@sitepen.com>, Shawn Wilsher <sdwilsh@mozilla.com>, public-webapps WG <public-webapps@w3.org>, Arun Ranganathan <aranganathan@mozilla.com>, Jonas Sicking <sicking@mozilla.com>
On Mar 12, 2010, at 9:05 AM, Aaron Boodman wrote: > Looking at just this snip: > > function findFred(db) { > db.request.onsuccess = function() { > var index = db.request.result; > index.request.onsuccess = function() { > var matching = index.request.result; > if (matching) > report(matching.isbn, matching.name, matching.author); > else > report(null); > } > index.get('fred'); > } > db.openIndex('BookAuthor'); > } > > This example is hard to read where the callback is setup before the > call like this. Without making any API changes, I think you could > improve things: > > db.openIndex('BookAuthor'); > db.request.onsuccess = function() { > ... > }; > > You just have to make sure that the API guarantees that > onsuccess/onfailure will always be called in a separate event, which > is important anyway for consistency. This seems like a light-weight enough requirement that can improve program comprehension.
Received on Saturday, 13 March 2010 09:46:16 UTC