Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In CouchDB shows, what does 'this' refer to?

I'm trying to understand CouchDB and couchapp, and as I'm going through I'm seeing a dearth of the use of 'this' in any given context. I understand that show objects get the document and the request, and are allowed to operate on them with lists and views. These operations are all Javascript objects. But CouchApp also seems to store, as strings, all sorts of things: README files, Mustache templates, and so on. It must have access to them somehow. Does the this operator in the context of a show provide access to the design document root in some way, giving one access to objects by some means other than the require syntax?

In Javascript, this has to be defined somehow in every context, specifically "There is a this value associated with every active execution context. The this value depends on the caller and the type of code being executed and is determined when control enters the execution context. The this value associated with an execution context is immutable" (ECMA-262 Spec, 3rd edition, section 10.1.7). What does it mean in the context of an executing CouchDB design doc show function? A view or list function?

like image 728
Elf Sternberg Avatar asked Jul 06 '11 02:07

Elf Sternberg


1 Answers

The this variable, in all cases (_list, _show, _update) is the design document itself.

(Strictly speaking, it refers to a JavaScript object representation of the design document that contains the list/show/view function you are operating out of.)

like image 92
Dominic Barnes Avatar answered Oct 09 '22 09:10

Dominic Barnes