couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yohei SASAKI <yss...@gmail.com>
Subject differences in the 'instanceof' operation between CouchDB view and couchjs.
Date Tue, 07 Apr 2009 20:05:55 GMT
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/

Mime
View raw message