<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="https://mg.to" xmlns:dc="https://purl.org/dc/elements/1.1/">
<channel>
 <title>mg.to - Invisible JavaScript functions - Comments</title>
 <link>https://mg.to/2004/09/17/invisible-javascript-functions</link>
 <description>Comments for &quot;Invisible JavaScript functions&quot;</description>
 <language>en</language>
<item>
 <title>Invoke pdf embedded Javascript from C#.NET</title>
 <link>https://mg.to/2004/09/17/invisible-javascript-functions#comment-6141</link>
 <description>&lt;p&gt;Hi Michael,&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m working on a C#.NET desktop application which creates pdf files.  The files are generated by populating pre-existing pdf templates.  These templates contain document level javascript.  My question, how do I invoke the embedded document level javascript from my C#.NET desktop application?  I&amp;#8217;ve been studying the Adobe SDK, etc but haven&amp;#8217;t had any luck with the actual implementation.  Any advice would be much appreciated, thanks!&lt;/p&gt;</description>
 <pubDate>Tue, 19 May 2009 21:27:21 +0000</pubDate>
 <dc:creator>Jason</dc:creator>
 <guid isPermaLink="false">comment 6141 at https://mg.to</guid>
</item>
<item>
 <title>Invisible JavaScript functions</title>
 <link>https://mg.to/2004/09/17/invisible-javascript-functions</link>
 <description>&lt;p&gt;If you&amp;#8217;re writing document-level JavaScript code in a PDF file, any variables you declare or assign to outside a function are created in the global object, which is the PDF document.&lt;/p&gt;

&lt;p&gt;Suppose we have a PDF with this code as a document script, which creates three variables in three different ways:&lt;/p&gt;

&lt;div style=&quot;padding: 5px !important; border: 1px solid rgb(253,187,134) !important; background-color: rgb(255,253,245) !important; font-family: Verdana,sans-serif !important;&quot;&gt;&lt;div style=&quot;background-color: rgb(255,250,238) !important;&quot;&gt;&lt;div class=&quot;geshi-javascript&quot;&gt;&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; myVar = &lt;span style=&quot;color: #CC0000;&quot;&gt;11&lt;/span&gt;;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// declare a variable&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
myNoVar = &lt;span style=&quot;color: #CC0000;&quot;&gt;22&lt;/span&gt;;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// assign to a global variable&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #C00000;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;myProp&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;33&lt;/span&gt;;&amp;nbsp; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// create a document property &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If we load this PDF and examine its variables in the JavaScript console, we see that each of the three variables is defined both as a global variable and as a property of &lt;code&gt;this&lt;/code&gt;, the document object. That seems surprising until you consider that in Acrobat JavaScript, the document object &lt;em&gt;is&lt;/em&gt; the global object.&lt;/p&gt;

&lt;pre&gt;&lt;strong&gt;myVar&lt;/strong&gt;
11
&lt;strong&gt;this.myVar&lt;/strong&gt;
11
&lt;strong&gt;myNoVar&lt;/strong&gt;
22
&lt;strong&gt;this.myNoVar&lt;/strong&gt;
22
&lt;strong&gt;myProp&lt;/strong&gt;
33
&lt;strong&gt;this.myProp&lt;/strong&gt;
33&lt;/pre&gt;

(Keyboard input is in &lt;code&gt;&lt;strong&gt;bold&lt;/strong&gt;&lt;/code&gt;, and we type Ctrl+Enter at the end of each line to evaluate the expression.)

When you&amp;#8217;re writing code, you don&amp;#8217;t want to pollute the document object&amp;#8217;s namespace needlessly. You can wrap up your code in a function, so that variables you create with a &lt;code&gt;var&lt;/code&gt; statement are local to the function.

Adobe Acrobat encourages this by creating a function for you when you add a document script. If you use Acrobat&amp;#8217;s &lt;strong&gt;Document JavaScripts&lt;/strong&gt; dialog to add a script called &lt;code&gt;DocScript&lt;/code&gt;, you&amp;#8217;ll get an empty function to fill in:

&lt;div style=&quot;padding: 5px !important; border: 1px solid rgb(253,187,134) !important; background-color: rgb(255,253,245) !important; font-family: Verdana,sans-serif !important;&quot;&gt;&lt;div style=&quot;background-color: rgb(255,250,238) !important;&quot;&gt;&lt;div class=&quot;geshi-javascript&quot;&gt;&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; DocScript&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;


Of course, you need to call this function, so you may end up with code like this:

&lt;div style=&quot;padding: 5px !important; border: 1px solid rgb(253,187,134) !important; background-color: rgb(255,253,245) !important; font-family: Verdana,sans-serif !important;&quot;&gt;&lt;div style=&quot;background-color: rgb(255,250,238) !important;&quot;&gt;&lt;div class=&quot;geshi-javascript&quot;&gt;&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; DocScript&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; doc &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; myVar1 = &lt;span style=&quot;color: #CC0000;&quot;&gt;11&lt;/span&gt;;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; myNoVar1 = &lt;span style=&quot;color: #CC0000;&quot;&gt;22&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; doc.&lt;span style=&quot;color: #006600;&quot;&gt;myProp1&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;33&lt;/span&gt;;&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;br /&gt;&lt;/div&gt;
DocScript&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #C00000;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;


Besides creating a scope for local variables, the function lets the code refer to the document object as &lt;code&gt;doc&lt;/code&gt; instead of &lt;code&gt;this&lt;/code&gt;. We didn&amp;#8217;t have to do that, but I like to be able to use &lt;code&gt;doc.whatever&lt;/code&gt; instead of &lt;code&gt;this.whatever&lt;/code&gt; for document properties.

If we look at these variables in the console window, the results are different:

&lt;pre&gt;&lt;strong&gt;myVar1&lt;/strong&gt;
ReferenceError: myVar1 is not defined
1:Console:Exec
undefined
&lt;strong&gt;this.myVar1&lt;/strong&gt;
undefined
&lt;strong&gt;myNoVar1&lt;/strong&gt;
22
&lt;strong&gt;this.myNoVar1&lt;/strong&gt;
22
&lt;strong&gt;myProp1&lt;/strong&gt;
33
&lt;strong&gt;this.myProp1&lt;/strong&gt;
33&lt;/pre&gt;

As expected, &lt;code&gt;myVar1&lt;/code&gt; does not show up either in the global object or the document object; it is local to the function. &lt;code&gt;myVar2&lt;/code&gt; does (because we didn&amp;#8217;t use &lt;code&gt;var&lt;/code&gt;), as does &lt;code&gt;myProp1&lt;/code&gt; (because we created it as a property of the doc object).

The difference between &lt;code&gt;myVar1&lt;/code&gt; and &lt;code&gt;this.myVar1&lt;/code&gt; is expected too. It&amp;#8217;s an error to reference a variable name that does not exist, so &lt;code&gt;myVar1&lt;/code&gt; throws a &lt;code&gt;ReferenceError&lt;/code&gt; exception. But it&amp;#8217;s not an error to reference a nonexistent property of an object&amp;#151;the reference merely returns the &lt;code&gt;undefined&lt;/code&gt; value. So &lt;code&gt;this.myVar1&lt;/code&gt; returns &lt;code&gt;undefined&lt;/code&gt; without error.

But we&amp;#8217;ve still put one name in the document object:

&lt;pre&gt;
&lt;strong&gt;DocScript&lt;/strong&gt;

function DocScript(doc) {
    var myVar1 = 11;
    myNoVar1 = 22;
    doc.myProp1 = 33;
}

&lt;strong&gt;this.DocScript&lt;/strong&gt;

function DocScript(doc) {
    var myVar1 = 11;
    myNoVar1 = 22;
    doc.myProp1 = 33;

}
&lt;/pre&gt;

&lt;p&gt;To avoid even this bit of namespace clutter, we can define an anonymous function and call it on the spot:&lt;/p&gt;

&lt;div style=&quot;padding: 5px !important; border: 1px solid rgb(253,187,134) !important; background-color: rgb(255,253,245) !important; font-family: Verdana,sans-serif !important;&quot;&gt;&lt;div style=&quot;background-color: rgb(255,250,238) !important;&quot;&gt;&lt;div class=&quot;geshi-javascript&quot;&gt;&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; doc &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; myVar2 = &lt;span style=&quot;color: #CC0000;&quot;&gt;11&lt;/span&gt;;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; myNoVar2 = &lt;span style=&quot;color: #CC0000;&quot;&gt;22&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; doc.&lt;span style=&quot;color: #006600;&quot;&gt;myProp2&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;33&lt;/span&gt;;&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #C00000;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The console results for &lt;code&gt;myVar2&lt;/code&gt;, etc. are the same as the previous example with the named function, so I won&amp;#8217;t repeat them. But unlike the named function, we haven&amp;#8217;t added any symbols at all to the document or global object.&lt;/p&gt;

&lt;p&gt;Why the extra parentheses? &lt;code&gt;function(){}&lt;/code&gt; is the simplest possible anonymous function, but if we try to call it using &lt;code&gt;function(){}()&lt;/code&gt; it&amp;#8217;s a syntax error. However, if we wrap the entire function inside a pair of parentheses, then we can follow that with &lt;code&gt;()&lt;/code&gt; to call it: &lt;code&gt;(function(){})()&lt;/code&gt; is legal JavaScript.&lt;/p&gt;

&lt;p&gt;The same trick works when you want to add a nested scope inside a function. The way you would do this in C doesn&amp;#8217;t work in JavaScript:&lt;/p&gt;

&lt;div style=&quot;padding: 5px !important; border: 1px solid rgb(253,187,134) !important; background-color: rgb(255,253,245) !important; font-family: Verdana,sans-serif !important;&quot;&gt;&lt;div style=&quot;background-color: rgb(255,250,238) !important;&quot;&gt;&lt;div class=&quot;geshi-javascript&quot;&gt;&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; noscope&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; i = &lt;span style=&quot;color: #CC0000;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; console.&lt;span style=&quot;color: #006600;&quot;&gt;println&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// This {} does not introduce a scope as in C&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; i = &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.&lt;span style=&quot;color: #006600;&quot;&gt;println&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; console.&lt;span style=&quot;color: #006600;&quot;&gt;println&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;noscope&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That code prints:&lt;/p&gt;

&lt;pre&gt;1
2
2&lt;/pre&gt;

&lt;p&gt;because there is only one variable named &lt;code&gt;i&lt;/code&gt; in the entire function, even though we&amp;#8217;ve (incorrectly) tried to add an inner scope with its own variable &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In fact, if you load that function into &lt;a href=&quot;https://www.activestate.com/Products/Komodo/&quot;&gt;ActiveState Komodo&lt;/a&gt;, it puts a green squiggly line under the inner &lt;code&gt;var i = 2;&lt;/code&gt; complaining &amp;ldquo;strict warning: redeclaration of var i&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;But if we use a nested anonymous function:&lt;/p&gt;

&lt;div style=&quot;padding: 5px !important; border: 1px solid rgb(253,187,134) !important; background-color: rgb(255,253,245) !important; font-family: Verdana,sans-serif !important;&quot;&gt;&lt;div style=&quot;background-color: rgb(255,250,238) !important;&quot;&gt;&lt;div class=&quot;geshi-javascript&quot;&gt;&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; withscope&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; i = &lt;span style=&quot;color: #CC0000;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; console.&lt;span style=&quot;color: #006600;&quot;&gt;println&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; i = &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.&lt;span style=&quot;color: #006600;&quot;&gt;println&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; console.&lt;span style=&quot;color: #006600;&quot;&gt;println&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color:rgb(255,234,216);&quot;&gt;withscope&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;color: #0000FF;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;it prints:&lt;/p&gt;

&lt;pre&gt;
1
2
1&lt;/pre&gt;

&lt;p&gt;which indicates that the nested function introduced a new scope.&lt;/p&gt;
</description>
 <comments>https://mg.to/2004/09/17/invisible-javascript-functions#comments</comments>
 <category domain="https://mg.to/topics/programming/acrobat">Acrobat</category>
 <category domain="https://mg.to/topics/programming/javascript">JavaScript</category>
 <category domain="https://mg.to/topics/programming">Programming</category>
 <pubDate>Fri, 17 Sep 2004 00:24:13 +0000</pubDate>
 <dc:creator>Michael Geary</dc:creator>
 <guid isPermaLink="false">47 at https://mg.to</guid>
</item>
</channel>
</rss>
