couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James A. Duncan" <ja...@reasonablysmart.com>
Subject 'this' in map functions
Date Sun, 14 Dec 2008 16:22:03 GMT

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") {


Mime
View raw message