<?xml version="1.0"?>
<rss version="2.0">
<channel>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/</link>
<title>helma.org/wiki/Helma NG/Modules and Scopes</title>
<description>Updates for Page helma.org/wiki/Helma NG/Modules and Scopes</description>
<pubDate>Thu, 24 May 2012 04:33:35 +0000</pubDate>
<item>
<title>Version 16</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=16</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;19&lt;/td&gt;&lt;td&gt;Module names are derived from a module&#39;s file name by removing the &amp;quot;.js&amp;quot; extension and &lt;span class=&#39;diffremoved&#39;&gt;replacing the &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;using &amp;quot;/&amp;quot; as &lt;/span&gt;path &lt;span class=&#39;diffremoved&#39;&gt;separators with dots&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;item separator&lt;/span&gt;. Thus, a module residing in file helma/http.js can be referred to as &#39;&lt;span class=&#39;diffremoved&#39;&gt;helma.http&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;helma/http&lt;/span&gt;&#39;. When a module is loaded, Helma NG defines a property called &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; and sets it to the module name.&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;Helma NG uses a module path to resolve module names. By default, the module path consists of the application directory and the modules directory in the Helma NG installation. It is possible to add directories and zip archives to the module path &lt;span class=&#39;diffremoved&#39;&gt;through &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;using the HELMA_MODULE_PATH environment variable or &lt;/span&gt;command line arguments to the Helma NG runtime and shell. When asked to import a module, Helma walks along the module path until it finds a module matching the name. If no matching module can be found, an error is thrown.&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;The global &amp;lt;code&amp;gt;import()&amp;lt;/code&amp;gt; function loads a module into a module scope and creates a reference in the caller&#39;s scope pointing to the imported scope. The imported module&#39;s name is used as property name in the calling module. For instance, the following statement will load the &lt;span class=&#39;diffremoved&#39;&gt;&amp;lt;code&amp;gt;helma.http&amp;lt;/code&amp;gt; &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;lt;code&amp;gt;helma/http&amp;lt;/code&amp;gt; &lt;/span&gt;module and add it as &amp;lt;code&amp;gt;helma.http&amp;lt;/code&amp;gt; to the scope of the calling module. &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;29&lt;/td&gt;&lt;td&gt;&amp;nbsp; import(&#39;&lt;span class=&#39;diffremoved&#39;&gt;helma.http&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;helma/http&lt;/span&gt;&#39;);&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;35&lt;/td&gt;&lt;td&gt;&amp;nbsp; var http = require(&#39;&lt;span class=&#39;diffremoved&#39;&gt;helma.http&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;helma/http&lt;/span&gt;&#39;);&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;41&lt;/td&gt;&lt;td&gt;&amp;nbsp; include(&#39;&lt;span class=&#39;diffremoved&#39;&gt;helma.skin&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;helma/skin&lt;/span&gt;&#39;);&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;45&lt;/td&gt;&lt;td&gt;If a function imported using include() wants to access properties or functions of its importing scope, it can do by either accepting the scope as an argument to the function, or by using the &amp;lt;code&amp;gt;this&amp;lt;/code&amp;gt; keyword, which contains the object the function was called on. In fact, the render() function in module &lt;span class=&#39;diffremoved&#39;&gt;helma.skin &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;helma/skin &lt;/span&gt;uses this to load a skin resource from a location relative to the importing module&#39;s file rather than itself.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Wed, 13 May 2009 12:53:30 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 15</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=15</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&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;&amp;lt;!-- diagram is outdated/wrong!&amp;nbsp; &lt;/span&gt;== Module &lt;span class=&#39;diffremoved&#39;&gt;Scope&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;Scope --&amp;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;diffremoved&#39;&gt;&amp;lt;% &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;lt;!-- % &lt;/span&gt;this.image &#39;scopes-ng-small.png&#39; &lt;span class=&#39;diffremoved&#39;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;% --&amp;gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Fri, 30 Jan 2009 16:08:39 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 14</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=14</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;27&lt;/td&gt;&lt;td&gt;The global &amp;lt;code&amp;gt;import()&amp;lt;/code&amp;gt; function &lt;span class=&#39;diffremoved&#39;&gt;allows to load &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;loads &lt;/span&gt;a module into a &lt;span class=&#39;diffremoved&#39;&gt;namespace of &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;module scope and creates a reference in &lt;/span&gt;the &lt;span class=&#39;diffremoved&#39;&gt;calling module&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;caller&#39;s scope pointing to the imported scope&lt;/span&gt;. &lt;span class=&#39;diffremoved&#39;&gt;By default, the namespace &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;The imported module&#39;s name &lt;/span&gt;is &lt;span class=&#39;diffremoved&#39;&gt;the same &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;used &lt;/span&gt;as &lt;span class=&#39;diffadded&#39;&gt;property name in &lt;/span&gt;the &lt;span class=&#39;diffremoved&#39;&gt;module name&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;calling module&lt;/span&gt;. For instance, the following statement will load the &amp;lt;code&amp;gt;helma.http&amp;lt;/code&amp;gt; module and add it as &amp;lt;code&amp;gt;helma.http&amp;lt;/code&amp;gt; to the scope of the calling module. &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;30&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;31&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;== require()&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;32&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;33&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;The global &amp;lt;code&amp;gt;require()&amp;lt;/code&amp;gt; function loads a module into a module scope and returns the scope object to the caller.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;34&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;35&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; var http = require(&#39;helma.http&#39;);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Sun, 25 Jan 2009 20:04:41 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 13</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=13</link>
<description>&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;One of the cornerstones of Helma NG, and one that distinguishes it from every other JavaScript runtime out there, is how it handles modules and scopes. See &lt;span class=&#39;diffremoved&#39;&gt;*/wiki/Modules &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;*Modules &lt;/span&gt;and in Helma &lt;span class=&#39;diffremoved&#39;&gt;NG* &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;NG|http://dev.helma.org/wiki/Modules+and+Scopes+in+Helma+NG/* &lt;/span&gt;for a higher level overview of the module system in Helma NG.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Sun, 25 Jan 2009 19:58:02 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 12</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=12</link>
<description>&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;One of the cornerstones of Helma NG, and one that distinguishes it from every other JavaScript runtime out there, is how it handles modules and scopes. See &lt;span class=&#39;diffremoved&#39;&gt;*Modules &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;*/wiki/Modules &lt;/span&gt;and in Helma NG* for a higher level overview of the module system in Helma NG.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Sun, 25 Jan 2009 19:57:38 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 11</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=11</link>
<description>&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;One of the cornerstones of Helma NG, and one that distinguishes it from every other JavaScript runtime out there, is how it handles modules and scopes. &lt;span class=&#39;diffadded&#39;&gt;See *Modules and in Helma NG* for a higher level overview of the module system in Helma NG.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Sun, 25 Jan 2009 19:57:19 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 10</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=10</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;51&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;== The shared global scope&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;52&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;53&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;== The per-thread global scope&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;54&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;55&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;== Metaprogramming&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;56&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;57&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;Modules automatically recognize functions following the *JSAdapter|http://blogs.sun.com/sundararajan/entry/self_javascript_and_jsadapter* syntax and will invoke these functions for property access if they are defined. For instance, if you define a function called &amp;lt;code&amp;gt;__get__&amp;lt;/code&amp;gt; in your module, it will be called to lookup properties. You can access the &amp;quot;raw&amp;quot; properties defined in your modules in your JSAdapter functions.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;58&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;59&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; var bar = &amp;quot;BAR&amp;quot;;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;60&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;61&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; function __get__(name) {&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;62&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; &amp;nbsp; if (name == &amp;quot;foobar&amp;quot;) {&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;63&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return &amp;quot;foo&amp;quot; + bar;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;64&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;65&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; &amp;nbsp; // leave this away if you don&#39;t want to expose &amp;quot;raw&amp;quot; properties&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;66&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; &amp;nbsp; return this[name];&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;67&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Sun, 25 Jan 2009 19:55:27 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 9</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=9</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&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;diffremoved&#39;&gt;importModule()&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;import()&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;The global &lt;span class=&#39;diffremoved&#39;&gt;&amp;lt;code&amp;gt;importModule()&amp;lt;/code&amp;gt; &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;lt;code&amp;gt;import()&amp;lt;/code&amp;gt; &lt;/span&gt;function allows to load a module into a namespace of the calling module. By default, the namespace is the same as the module name. For instance, the following statement will load the &amp;lt;code&amp;gt;helma.http&amp;lt;/code&amp;gt; module and add it as &amp;lt;code&amp;gt;helma.http&amp;lt;/code&amp;gt; to the scope of the calling module. &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;29&lt;/td&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&#39;diffremoved&#39;&gt;importModule(&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;import(&lt;/span&gt;&#39;helma.http&#39;);&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;31&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;Optionally, importModule() takes a second argument that allows to override the namespace to place the imported module. The following call will put the imported module into &amp;lt;code&amp;gt;http&amp;lt;/code&amp;gt;, dumping the &lt;/span&gt;&lt;span class=&#39;diffremoved&#39;&gt;&#39;helma&#39;&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;==&lt;/span&gt;&amp;nbsp;&lt;span class=&#39;diffremoved&#39;&gt;prefix and making it more convenient to access:&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;include()&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;33&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; importModule(&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;Another way of using the functionality of a module is to add one or more properties or functions from the module to one&lt;/span&gt;&#39;&lt;span class=&#39;diffremoved&#39;&gt;helma&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;s own top level scope&lt;/span&gt;.&lt;span class=&#39;diffremoved&#39;&gt;http&#39;&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt; For example&lt;/span&gt;, &lt;span class=&#39;diffremoved&#39;&gt;&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;you could use the following statement to add the Client constructor to your local module&lt;/span&gt;&#39;&lt;span class=&#39;diffremoved&#39;&gt;http&#39;);&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;s top level scope:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;35&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;==&lt;/span&gt;&amp;nbsp;&lt;span class=&#39;diffremoved&#39;&gt;importFromModule()&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt; include(&#39;helma.skin&#39;);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;37&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;Another way of using the functionality of a module is to add one or more properties or functions from the module to one&#39;s own top level scope. For example, if you only need the Client class from the helma.http module, you could use the following statement to add the Client constructor to your local module&#39;s top level scope:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;38&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;39&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&amp;nbsp; importFromModule(&#39;helma.skin&#39;, &#39;render&#39;);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;40&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffremoved&#39;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;40&lt;/td&gt;&lt;td&gt;If a function imported using &lt;span class=&#39;diffremoved&#39;&gt;importFromModule() &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;include() &lt;/span&gt;wants to access properties or functions of its importing scope, it can do by either accepting the scope as an argument to the function, or by using the &amp;lt;code&amp;gt;this&amp;lt;/code&amp;gt; keyword, which contains the object the function was called on. In fact, the render() function in module helma.skin uses this to load a skin resource from a location relative to the importing module&#39;s file rather than itself.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Sun, 25 Jan 2009 19:51:13 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 8</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=8</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;47&lt;/td&gt;&lt;td&gt;By default, Helma NG creates &lt;span class=&#39;diffremoved&#39;&gt;earch &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;each &lt;/span&gt;module once per request. This means that if a module is loaded from several other modules in the same application, you be sure that you deal with the actual same module instance and scope throughout each request, but are isolated from other requests that may be running at the same time. &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Thu, 25 Sep 2008 22:00:17 +0000</pubDate>
<author>anton</author>
</item>
<item>
<title>Version 7</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=7</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&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;diffremoved&#39;&gt;=&lt;/span&gt; Modules&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;diffremoved&#39;&gt;First, if one &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;If a &lt;/span&gt;module wants to make use of another module, it needs to import the other module. Helma NG provides two global functions for this, one to import a module into a discrete namespace, and another to import some or all properties of a module into its own scope. &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;diffremoved&#39;&gt;=&lt;/span&gt; Module Scope&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;diffremoved&#39;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&#39;diffremoved&#39;&gt;importModule()&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;Module naming&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;Module names are derived from a module&#39;s file name by removing the &lt;/span&gt;&lt;span class=&#39;diffremoved&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&#39;diffremoved&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;.js&amp;quot; extension and replacing the path separators with dots. Thus, a module residing in file helma/http.js can be referred to as &lt;/span&gt;&lt;span class=&#39;diffremoved&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;&#39;helma.http&#39;.&lt;/span&gt;&amp;nbsp;&lt;span class=&#39;diffremoved&#39;&gt;importFromModule()&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;When a module is loaded, Helma NG defines a property called &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; and sets it to the module name.&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;diffremoved&#39;&gt;===&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;Helma NG uses a module path to resolve module names.&lt;/span&gt;&amp;nbsp;&lt;span class=&#39;diffremoved&#39;&gt;Module sharing &lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;By default, the module path consists of the application directory &lt;/span&gt;and &lt;span class=&#39;diffremoved&#39;&gt;caching&lt;/span&gt;&lt;span class=&#39;diffadded&#39;&gt;the modules directory in the Helma NG installation. It is possible to add directories and zip archives to the module path through command line arguments to the Helma NG runtime and shell. When asked to import a module, Helma walks along the module path until it finds a module matching the name. If no matching module can be found, an error is thrown.&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;Usually, Helma modules consist of only one JavaScript file. In some cases, it is preferable to split a single module over multiple files. For these cases, Helma provides a feature to load all the JavaScript files contained in a directory into one single module. Use a module name ending with &#39;.\*&#39; to use this, e.g. &amp;lt;code&amp;gt;&#39;reallybigmodule.\*&#39;&amp;lt;/code&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;&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;== importModule()&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;&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;The global &amp;lt;code&amp;gt;importModule()&amp;lt;/code&amp;gt; function allows to load a module into a namespace of the calling module. By default, the namespace is the same as the module name. For instance, the following statement will load the &amp;lt;code&amp;gt;helma.http&amp;lt;/code&amp;gt; module and add it as &amp;lt;code&amp;gt;helma.http&amp;lt;/code&amp;gt; to the scope of the calling module. &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;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;29&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; importModule(&#39;helma.http&#39;);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;30&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;31&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;Optionally, importModule() takes a second argument that allows to override the namespace to place the imported module. The following call will put the imported module into &amp;lt;code&amp;gt;http&amp;lt;/code&amp;gt;, dumping the &#39;helma&#39; prefix and making it more convenient to access:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;32&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;33&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; importModule(&#39;helma.http&#39;, &#39;http&#39;);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;34&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;35&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;== importFromModule()&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;36&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;37&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;Another way of using the functionality of a module is to add one or more properties or functions from the module to one&#39;s own top level scope. For example, if you only need the Client class from the helma.http module, you could use the following statement to add the Client constructor to your local module&#39;s top level scope:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;38&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;39&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; importFromModule(&#39;helma.skin&#39;, &#39;render&#39;);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;40&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;41&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;Now the really nice thing about this is that because of JavaScript&#39;s static scoping, the render function continues to &#39;live&#39; in its original scope, which is the one defined by the helma.skin module. It can therefore call all global functions defined in the helma.skin module without using any prefix and without fear of unintentionally calling something defined elsewhere. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;42&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;43&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;If a function imported using importFromModule() wants to access properties or functions of its importing scope, it can do by either accepting the scope as an argument to the function, or by using the &amp;lt;code&amp;gt;this&amp;lt;/code&amp;gt; keyword, which contains the object the function was called on. In fact, the render() function in module helma.skin uses this to load a skin resource from a location relative to the importing module&#39;s file rather than itself.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;44&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;45&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;== Module loading, sharing and caching&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;46&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;32&lt;/td&gt;&lt;td&gt;==&lt;span class=&#39;diffremoved&#39;&gt;=&lt;/span&gt; The shared global scope&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;34&lt;/td&gt;&lt;td&gt;==&lt;span class=&#39;diffremoved&#39;&gt;=&lt;/span&gt; The per-thread global scope&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;36&lt;/td&gt;&lt;td&gt;==&lt;span class=&#39;diffremoved&#39;&gt;=&lt;/span&gt; Metaprogramming&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Fri, 23 May 2008 14:06:29 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 6</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=6</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;40&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Fri, 23 May 2008 13:07:28 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 5</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=5</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;29&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;This will result in your module scope to be kept alive across and shared among requests.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;30&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;33&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;34&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;=== Metaprogramming&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;35&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;36&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;Modules automatically recognize functions following the *JSAdapter|http://blogs.sun.com/sundararajan/entry/self_javascript_and_jsadapter* syntax and will invoke these functions for property access if they are defined. For instance, if you define a function called &amp;lt;code&amp;gt;__get__&amp;lt;/code&amp;gt; in your module, it will be called to lookup properties. You can access the &amp;quot;raw&amp;quot; properties defined in your modules in your JSAdapter functions.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;37&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;38&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; var bar = &amp;quot;BAR&amp;quot;;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;39&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;40&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; function __get__(name) {&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;41&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; &amp;nbsp; if (name == &amp;quot;foobar&amp;quot;) {&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;42&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return &amp;quot;foo&amp;quot; + bar;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;43&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;44&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; &amp;nbsp; // leave this away if you don&#39;t want to expose &amp;quot;raw&amp;quot; properties&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;45&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; &amp;nbsp; return this[name];&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;width:2em; color:#999;&quot;&gt;46&lt;/td&gt;&lt;td&gt;&lt;span class=&#39;diffadded&#39;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Fri, 23 May 2008 13:07:16 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 4</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=4</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&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;By default, Helma NG creates earch module once per request. This means that if a module is loaded from several other modules in the same application, you be sure that you deal with the actual same module instance and scope throughout each request, but are isolated from other requests that may be running at the same time. &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;&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;Sometimes it is desirable to have a module instantiated only once, and shared among all requests. You can achieve this by defining a property called &amp;lt;code&amp;gt;__shared__&amp;lt;/code&amp;gt; in your module and giving it the value &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;:&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;&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;nbsp; var __shared__ = true;&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>Fri, 23 May 2008 12:58:45 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 3</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=3</link>
<description>&lt;div class=&#39;diffbody&#39;&gt;&lt;table&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;% this.image &#39;scopes-ng-small.png&#39; %&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;&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;&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;=== Module sharing and caching&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Fri, 23 May 2008 12:52:36 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 2</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/history.diff?v=2</link>
<description>&lt;ul class=&#39;diffproperties&#39;&gt;&lt;li&gt;Deleted &lt;span class=&#39;diffpropname&#39;&gt;tags&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;</description>
<pubDate>Fri, 23 May 2008 12:48:07 +0000</pubDate>
<author>hannes</author>
</item>
<item>
<title>Version 1</title>
<link>http://helma.org/wiki/Helma+NG/Modules+and+Scopes/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;helma ng&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;One of the cornerstones of Helma NG, and one that distinguishes it from every other JavaScript runtime out there, is how it handles modules and scopes. &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;=== Modules&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;Helma NG handles JavaScript resources as Modules. If this evokes associations to *Python|http://docs.python.org/tut/node8.html* it is fully intentional, because NG Modules work and feel very much like *Python Modules|http://effbot.org/zone/import-confusion.htm*. &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;First, if one module wants to make use of another module, it needs to import the other module. Helma NG provides two global functions for this, one to import a module into a discrete namespace, and another to import some or all properties of a module into its own scope. &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;Now the special thing about Helma NG is that the two modules (one doing the import, the other being imported) are fully isolated from each other. The imported module does not have any way at all to access the importing module, and the importing module can only access the imported one via the namespace into which it imported it, or the properties and functions it explicitly imported from it. And what&#39;s more, you don&#39;t have to do anything special to accomplish this. You just write scripts with global functions and properties and never worry about stuff that is defined in other scripts. &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;The way Helma NG does this is by giving each Module its own top-level scope.&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;=== Module Scope&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;=== importModule()&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;&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;=== importFromModule()&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;&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;=== The shared global scope&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;=== The per-thread global scope&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</description>
<pubDate>Fri, 23 May 2008 12:39:27 +0000</pubDate>
<author>hannes</author>
</item>
</channel>
</rss>

