incubator-couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <jch...@gmail.com>
Subject Re: 'this' in map functions
Date Sun, 14 Dec 2008 21:12:26 GMT
James,

Glad to see you getting into the code base. CouchDB is surprisingly
easy to hack on once you get familiar with the different modules.

I think in this case its best to stick to the more functional style by
explicitly passing the doc in. Especially because we'd like to be
freezing the doc.

If you're interested in scripting server side JavaScript, keep an eye
out for the _external server module which is coming into trunk soon.
It proxies http requests to a JSON server, so you can pretty easily
build JavaScript responders.

The code is sitting in davisp's Github repo but should be moving to
trunk this week.

http://github.com/davisp/couchdb/commits/external3/ (see the last 4 commits)

Chris

On Sun, Dec 14, 2008 at 8:22 AM, James A. Duncan
<james@reasonablysmart.com> wrote:
>
> 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") {
>
>



-- 
Chris Anderson
http://jchris.mfdz.com

Mime
View raw message