<?xml version="1.0"?>
<rss version="2.0">
<channel>
<link>http://helma.org/wiki/on+Helma+1.6.x+and+the+scope+of+source+code+in+%22prototype%22+folders./</link>
<title>helma.org/wiki/on Helma 1.6.x and the scope of source code in &quot;prototype&quot; folders.</title>
<description>Updates for Page helma.org/wiki/on Helma 1.6.x and the scope of source code in &quot;prototype&quot; folders.</description>
<pubDate>Thu, 24 May 2012 18:21:07 +0000</pubDate>
<item>
<title>Version 2</title>
<link>http://helma.org/wiki/on+Helma+1.6.x+and+the+scope+of+source+code+in+%22prototype%22+folders./history.diff?v=2</link>
<description>&lt;ul class=&#39;diffproperties&#39;&gt;&lt;li&gt;Changed &lt;span class=&#39;diffpropname&#39;&gt;tags&lt;/span&gt; to &lt;span class=&#39;diffadded&#39;&gt;prototype, scope, rhino, functions, this&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;</description>
<pubDate>Wed, 06 Aug 2008 07:16:49 +0000</pubDate>
<author>breton</author>
</item>
<item>
<title>Version 1</title>
<link>http://helma.org/wiki/on+Helma+1.6.x+and+the+scope+of+source+code+in+%22prototype%22+folders./history.diff?v=1</link>
<description>&lt;ul class=&#39;diffproperties&#39;&gt;&lt;li&gt;Set &lt;span class=&#39;diffpropname&#39;&gt;tags&lt;/span&gt; to &lt;span class=&#39;diffadded&#39;&gt;prototype scope rhino functions this&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&#39;diffbody&#39;&gt;&lt;table&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;1&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;*.js files used in helma have a different and potentially confusing model for scope compared to client side javascript. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;2&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;3&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;The basics:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;4&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;5&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;In traditional client side scripting, the outermost scope in a Javascript source file is the global object. the keyword &amp;quot;this&amp;quot; also refers to that same global object in the outermost scope. In helma, this is only the case when a javascript source file is treated as a single file repository, or if it&#39;s in the &amp;quot;Global&amp;quot; folder of a multifile repository. In the case of javascript source files in a &amp;quot;prototype&amp;quot; folder however, the scopes do some interesting things. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;6&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;7&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;A prototype folder is a named folder in a multifile repository. When such a repository is added to an application, new native Java functions are added to the application&#39;s global scope, with the same names as the folders in the repository. These are the constructor functions, and calling one of them with the &amp;quot;new&amp;quot; operator produces a new HopObject. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;8&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;9&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;So for example, if a repository has a folder named &amp;quot;Page&amp;quot;, the application&#39;s global scope gets a function also called &amp;quot;Page&amp;quot;, and the code &amp;quot;new Page()&amp;quot; returns a new HopObject whose prototype is set to the value of Page.prototype.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;10&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;11&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;Now here&#39;s where things get interesting. If you place a Javascript source file in that Page folder, with a .js extension, the outermost scope for that source file is in fact, Page.prototype. The keyword &amp;quot;this&amp;quot; also refers to Page.prototype. This is nearly as advertised in all the Helma documentation. This makes it so that if you define a function in the source file, it becomes a new property of Page.prototype, and through Javascript prototypal inheritence, becomes a property of every instance of &amp;quot;Page&amp;quot;.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;12&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;13&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;The tricky and confusing part of all this is that this special prototype scope is not transferred to the interior of Page&#39;s function declarations. Instead, inside of a prototype&#39;s function, the scope is reset to the global object, and &amp;quot;this&amp;quot; naturally refers to whatever instance of &amp;quot;Page&amp;quot; you happen to call it on. So a bit of code like this, which may be considered normal on the client side:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;14&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;15&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;lt;pre&amp;gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;16&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;var title = &amp;quot;Untitled Page&amp;quot;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;17&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;function printTitle() {&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;18&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;print(title);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;19&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;}&amp;lt;/pre&amp;gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;20&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;21&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;doesn&#39;t work, unless you change it to something like this:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;22&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;23&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;lt;pre&amp;gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;24&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;var title = &amp;quot;Untitled Page&amp;quot;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;25&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;function printTitle() {&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;26&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;print(this.title);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;27&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;}&amp;lt;/pre&amp;gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;28&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Wed, 06 Aug 2008 04:59:22 +0000</pubDate>
<author>breton</author>
</item>
</channel>
</rss>

