From user-return-18187-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Tue Oct 4 12:05:11 2011 Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B58E6705D for ; Tue, 4 Oct 2011 12:05:11 +0000 (UTC) Received: (qmail 58119 invoked by uid 500); 4 Oct 2011 12:05:10 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 58085 invoked by uid 500); 4 Oct 2011 12:05:10 -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 58077 invoked by uid 99); 4 Oct 2011 12:05:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Oct 2011 12:05:09 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.216.180] (HELO mail-qy0-f180.google.com) (209.85.216.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Oct 2011 12:05:02 +0000 Received: by qyc1 with SMTP id 1so327042qyc.11 for ; Tue, 04 Oct 2011 05:04:40 -0700 (PDT) Received: by 10.43.48.198 with SMTP id ux6mr1748041icb.227.1317729880621; Tue, 04 Oct 2011 05:04:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.42.218.69 with HTTP; Tue, 4 Oct 2011 05:04:20 -0700 (PDT) In-Reply-To: References: From: Jason Smith Date: Tue, 4 Oct 2011 19:04:20 +0700 Message-ID: Subject: Re: Allowed contents of validate_doc_update field. To: user@couchdb.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org I would stick to a pure-function. What if you set `a =3D /not_bla/` in the function? But CouchDB might start many simultaneous Javascript processes, so you will not know the value of `a` later. I admit that sometimes I wish I could put constants and other things outside the function, for readability. P.S. /regex/.test(str) does not work on some builds of CouchDB (or rather, some builds of Spidermonkey) which are still in use. It is safer to use str.match(/regex) which I also find less readable :) On Tue, Oct 4, 2011 at 3:35 PM, Marcello Nuccio wrote: > Is it supported to put anything other than an anonymous function in > the validate_doc_update field of a design document? > > For example: > > =C2=A0 =C2=A0var a =3D /bla/; > =C2=A0 =C2=A0function (doc, oldDoc, userCtx, secObj) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!a.test(doc._id)) ... > =C2=A0 =C2=A0} > > is it supported or it can work only by coincidence. > > Thanks, > =C2=A0Marcello > --=20 Iris Couch