Return-Path: Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: (qmail 23156 invoked from network); 14 Dec 2008 16:22:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Dec 2008 16:22:35 -0000 Received: (qmail 18296 invoked by uid 500); 14 Dec 2008 16:22:47 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 18188 invoked by uid 500); 14 Dec 2008 16:22:47 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 18177 invoked by uid 99); 14 Dec 2008 16:22:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Dec 2008 08:22:47 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [67.207.128.215] (HELO toynbee.whoot.org) (67.207.128.215) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Dec 2008 16:22:25 +0000 Received: from [10.0.1.4] (bas1-montrealak-1128549450.dsl.bell.ca [67.68.76.74]) by toynbee.whoot.org (Postfix) with ESMTP id 035275C4C9 for ; Sun, 14 Dec 2008 16:22:04 +0000 (UTC) Message-Id: <46EDE237-E90E-419A-AEA4-9937F6852A3C@reasonablysmart.com> From: "James A. Duncan" To: dev@couchdb.apache.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Subject: 'this' in map functions Date: Sun, 14 Dec 2008 11:22:03 -0500 X-Mailer: Apple Mail (2.929.2) X-Virus-Checked: Checked by ClamAV on apache.org I've been following CouchDB for a while, but only started playing with it seriously very recently. One thing I keep catching myself with is that map functions receive the document as a parameter, and I keep looking for it in 'this'. Maybe that's because I spend too much time with JavaScript, or maybe it's because I don't spend enough time with CouchDB. A one-line patch follows, that allows for 'this' to be used as well as the positional arg. There may well be good reasons why this isn't sensible, and really it's just sugar, but I thought I'd dive in and give it a try. Regards, James. --- /Users/jduncan/oldmain.js 2008-12-14 11:04:11.000000000 -0500 +++ /opt/local/share/couchdb/server/main.js 2008-12-14 11:03:16.000000000 -0500 @@ -91,7 +91,7 @@ for (var i = 0; i < funs.length; i++) { map_results = []; try { - funs[i](doc); + funs[i].apply(doc, [ doc ]); buf.push(toJSON(map_results)); } catch (err) { if (err == "fatal_error") {