From user-return-4339-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Wed Apr 08 15:21:25 2009 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 20399 invoked from network); 8 Apr 2009 15:21:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Apr 2009 15:21:25 -0000 Received: (qmail 61695 invoked by uid 500); 8 Apr 2009 15:21:24 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 61634 invoked by uid 500); 8 Apr 2009 15:21:23 -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 Delivered-To: moderator for user@couchdb.apache.org Received: (qmail 81955 invoked by uid 99); 7 Apr 2009 20:06:23 -0000 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: domain of yssk22@gmail.com designates 209.85.198.232 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=zK3Ax2DOL4/CfCAIwogOzwCrDFhb7MHefcZnBuuXdE0=; b=eSuF7oS1RZNnGDDFsRo2+xz0ISaWgK81Z7i5gyd8huCmkza4cZ1DXf4WKN4EMj0hjk B7Vgt2DjfHelyU/KKXP1qU+xNhypjse/Fj78v8rZHtvSGJgIAkA+hjC0KpvviHuzR6kh fEFXhtrHKRVG2i9F4+ULIgeeNTCsVJOKKfvvQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=BxmS+5s5ot1bDLL2WrZcz++l5QwOOmoc09+CBNELZrH4HIed4oRntjQSJQc8Q6araI rEXt2rYuuBE/amh9+QFXo5s+2Q9GO30ZbpU8bGQHMzivF7b7SESL9tQ7iH3ja1l9tf3Q dauILeZUeyVdvXXYfg5cutTMFE8yXb8GhIQEE= MIME-Version: 1.0 Date: Wed, 8 Apr 2009 05:05:55 +0900 Message-ID: <717bc8230904071305h47cb441o6a64ebf9d83755f8@mail.gmail.com> Subject: differences in the 'instanceof' operation between CouchDB view and couchjs. From: Yohei SASAKI To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hi all, I came across a problem in my view script with the "instanceof" operation. Can anyone explain the cause of my problem duplicated by following steps? === 1. Add a document with Array into a database. { "_id": "oh_my_array", "_rev": "2-3397837489", "array_member": [ 1, 2, 3 ] } 2. Run the following map-only view. function(doc) { emit("0_raw_data", doc.array_member); emit("1_instanceof", (doc.array_member instanceof Array)); emit("2_constructor.name", doc.array_member.constructor.name); emit("3_typeof", (typeof doc.array_member)); } 3. Get the strange value in "1_instanceof" in Futon. (key, value) -> ("0_raw_data", [1,2,3]) ("1_instanceof", false); <-- why not true? ("2_constructor.name", "Array"); ("3_typeof", "object"); === # As above, "constructor.name" is an workaround instead of instanceof. I use CouchDB 0.9.0 (installed from the tarball on Apache) with JS 1.7(installed from MacPorts). And on couchjs standalone mode, the expression, 'instanceof Array' returns true as follows: === mac:~ yssk22$ cat a.js var doc = { "_id": "oh_my_array", "_rev": "2-3397837489", "array_member": [ 1, 2, 3 ] }; print(doc.array_member instanceof Array); mac:~ yssk22$ /usr/local/bin/couchjs a.js true === Thanks. -- Yohei SASAKI http://github.com/yssk22/