<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic What happens when another function is inside require([ ],function( )); in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-happens-when-another-function-is-inside/m-p/79570#M7295</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In AMD style codes, I don't understand what happens when a function is in inside the require([...], function() {}); for example, the following codes: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;require([...], function() { .....&amp;nbsp; function ABC () {a = c + b; } ..... });&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The function ABC is very confusing to me.&amp;nbsp; When the program runs, when will function ABC be executed?&amp;nbsp; To understand this, should I go study more dojo language? Thanks a lot!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Oct 2013 17:54:26 GMT</pubDate>
    <dc:creator>LeiZhou</dc:creator>
    <dc:date>2013-10-29T17:54:26Z</dc:date>
    <item>
      <title>What happens when another function is inside require([ ],function( ));</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-happens-when-another-function-is-inside/m-p/79570#M7295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In AMD style codes, I don't understand what happens when a function is in inside the require([...], function() {}); for example, the following codes: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;require([...], function() { .....&amp;nbsp; function ABC () {a = c + b; } ..... });&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The function ABC is very confusing to me.&amp;nbsp; When the program runs, when will function ABC be executed?&amp;nbsp; To understand this, should I go study more dojo language? Thanks a lot!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 17:54:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-happens-when-another-function-is-inside/m-p/79570#M7295</guid>
      <dc:creator>LeiZhou</dc:creator>
      <dc:date>2013-10-29T17:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: What happens when another function is inside require([ ],function( ));</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-happens-when-another-function-is-inside/m-p/79571#M7296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;In AMD style codes, I don't understand what happens when a function is in inside the require([...], function() {}); for example, the following codes: &lt;BR /&gt; &lt;PRE class="plain" name="code"&gt;require([...], function() { .....&amp;nbsp; function ABC () {a = c + b; } ..... });&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;The function ABC is very confusing to me.&amp;nbsp; When the program runs, when will function ABC be executed?&amp;nbsp; To understand this, should I go study more dojo language? Thanks a lot!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The ABC function lives in the scope of the require() function, but isn't executed unless you call it in the require function. It is only accessible inside that particular require function. This isn't really a Dojo specific issue. Modules simply scope functionality. But when you define() a module, unless you return something, it doesn't provide anything. This is why you may come across errors like variable equals 3 or something odd, because maybe you forgot to place a return in the module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To help illustrate, let's look at a define() module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;// ABCModule define([], function() { &amp;nbsp; function ABC (b, c) { &amp;nbsp;&amp;nbsp;&amp;nbsp; var a = c + b; &amp;nbsp;&amp;nbsp;&amp;nbsp; return a; &amp;nbsp; }&amp;nbsp; &amp;nbsp; return ABC; // defined modules should return something, object or function. });&amp;nbsp; // Main JS file require(['./ABCModule'], function(ABC) { &amp;nbsp; ABC(1, 2); // returns 3; });&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you didn't actually return ABC in the defined module, you would never be able to use it, as it's not exposed to the outside world.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AMD modules essentially use the revealing module pattern to share their innards (or the important parts anyway) with the everyone else.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript" rel="nofollow" target="_blank"&gt;http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript&lt;/A&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://requirejs.org/docs/whyamd.html#amd" rel="nofollow" target="_blank"&gt;http://requirejs.org/docs/whyamd.html#amd&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here are a couple of links that discuss scope.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://dailyjs.com/2012/07/23/js101-scope/" rel="nofollow" target="_blank"&gt;http://dailyjs.com/2012/07/23/js101-scope/&lt;/A&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope" rel="nofollow" target="_blank"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope&lt;/A&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://javascriptplayground.com/blog/2012/04/javascript-variable-scope-this/" rel="nofollow" target="_blank"&gt;http://javascriptplayground.com/blog/2012/04/javascript-variable-scope-this/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, you typically only have a single require() per application, an entry point to start the application. This SO answer covers if pretty nicely. &lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://stackoverflow.com/questions/11559270/what-is-the-main-difference-between-require-and-define-function-in-dojo-and" rel="nofollow" target="_blank"&gt;http://stackoverflow.com/questions/11559270/what-is-the-main-difference-between-require-and-define-function-in-dojo-and&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps a bit.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 18:17:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-happens-when-another-function-is-inside/m-p/79571#M7296</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2013-10-29T18:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: What happens when another function is inside require([ ],function( ));</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-happens-when-another-function-is-inside/m-p/79572#M7297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks a lot! It is a very useful information.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Oct 2013 18:13:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-happens-when-another-function-is-inside/m-p/79572#M7297</guid>
      <dc:creator>LeiZhou</dc:creator>
      <dc:date>2013-10-31T18:13:28Z</dc:date>
    </item>
  </channel>
</rss>

