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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 09:36:18

问题


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?


回答1:


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.)



来源:https://stackoverflow.com/questions/6591002/in-couchdb-shows-what-does-this-refer-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!