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, gi开发者_如何学JAVAving 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?
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.)
精彩评论