Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 30345 invoked from network); 3 Sep 2009 10:46:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Sep 2009 10:46:20 -0000 Received: (qmail 52247 invoked by uid 500); 3 Sep 2009 10:46:19 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 52171 invoked by uid 500); 3 Sep 2009 10:46:19 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 52160 invoked by uid 99); 3 Sep 2009 10:46:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2009 10:46:19 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [83.97.50.139] (HELO jan.prima.de) (83.97.50.139) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2009 10:46:08 +0000 Received: from [192.168.1.17] (f053001231.adsl.alicedsl.de [::ffff:78.53.1.231]) (AUTH: LOGIN jan, TLS: TLSv1/SSLv3,128bits,AES128-SHA) by jan.prima.de with esmtp; Thu, 03 Sep 2009 10:45:46 +0000 Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Mime-Version: 1.0 (Apple Message framework v1075.2) Subject: Re: View to find someone in a list in a document From: Jan Lehnardt In-Reply-To: <4AC31158-07A2-4A7B-AC08-42F07A026C13@googlemail.com> Date: Thu, 3 Sep 2009 12:45:44 +0200 Content-Transfer-Encoding: 7bit Message-Id: <4F4AE528-DA06-4CB6-9E3E-CC57F92A0D3C@apache.org> References: <51d0803c0909020925s75bdc063gd108f8c5618ca38c@mail.gmail.com> <9BE6119F-6D55-4293-B209-9D23F7A33484@googlemail.com>,<2A5814D7-3742-4FED-A451-31576904FFB3@apache.org> <4AC31158-07A2-4A7B-AC08-42F07A026C13@googlemail.com> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1075.2) X-Virus-Checked: Checked by ClamAV on apache.org 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 >