couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <...@apache.org>
Subject Re: View to find someone in a list in a document
Date Thu, 03 Sep 2009 10:45:44 GMT

On 3 Sep 2009, at 11:11, Simon Metson wrote:

> Hi,
> 	I'm not sure if there's a technical benefit of this syntax, but I  
> think I prefer reading it... Any JS wizards out there like to comment?

to get for(... in .. ) right you need to add:

a hasOwnProperty() call to account for prototypical inheritance  
behaviour.

In addition forEach and a closure can be optimised behind the scenes  
better.

Cheers
Jan
--






> Cheers
> Simon
>
> On 3 Sep 2009, at 09:53, Nils Breunese wrote:
>
>> I even learned that using for (... in ...) is not safe for use with  
>> arrays. I tend to use Array.forEach() [0] like this:
>>
>> ----
>> function(doc) {
>> if (doc.users) {
>>   doc.users.forEach(function(user) {
>>     emit(user, doc);
>>   });
>> }
>> }
>> ----
>>
>> I'm not very proficient in JavaScript, so maybe there is no real in  
>> advantage in the realm of CouchDB.
>>
>> Nils Breunese.
>>
>> [0] https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:forEach
>


Mime
View raw message