<?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 dojo declare &amp;amp;amp;amp; private instance members in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-declare-amp-amp-amp-private-instance-members/m-p/698357#M65036</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello -&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In looking into dojo modules, I'm simply trying to define a private instance member, and then eventually some get/set properties around them.&amp;nbsp; This is very easy to do with traditional JS object definitions.&amp;nbsp; In my research into dojo modules (via declare), this doesn't seem to be so simple.&amp;nbsp; I've seen that they can be identified as private via the leading "_" naming convention, but this doesn't actually make them private.&amp;nbsp; I've also seen how a private object can be declared within a module.&amp;nbsp; This essentially gives a private container for other private items, which is closer but not quite a simple private member.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wanted to know if I'm missing something, or if this is just how dojo modules work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Brian&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Mar 2014 13:11:21 GMT</pubDate>
    <dc:creator>BrianRassier</dc:creator>
    <dc:date>2014-03-03T13:11:21Z</dc:date>
    <item>
      <title>dojo declare &amp;amp;amp; private instance members</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-declare-amp-amp-amp-private-instance-members/m-p/698357#M65036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello -&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In looking into dojo modules, I'm simply trying to define a private instance member, and then eventually some get/set properties around them.&amp;nbsp; This is very easy to do with traditional JS object definitions.&amp;nbsp; In my research into dojo modules (via declare), this doesn't seem to be so simple.&amp;nbsp; I've seen that they can be identified as private via the leading "_" naming convention, but this doesn't actually make them private.&amp;nbsp; I've also seen how a private object can be declared within a module.&amp;nbsp; This essentially gives a private container for other private items, which is closer but not quite a simple private member.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wanted to know if I'm missing something, or if this is just how dojo modules work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Brian&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Mar 2014 13:11:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-declare-amp-amp-amp-private-instance-members/m-p/698357#M65036</guid>
      <dc:creator>BrianRassier</dc:creator>
      <dc:date>2014-03-03T13:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: dojo declare &amp; private instance members</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-declare-amp-amp-amp-private-instance-members/m-p/698358#M65037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That's actually how JavaScript &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype" rel="nofollow" target="_blank"&gt;prototypes&lt;/A&gt;&lt;SPAN&gt; work, not necessarily special to Dojo's declare method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anything added to the prototype is not really hidden. The underscore is more of a convention, not a rule. The same can be said for other languages like Python, there is &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;no real private&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What you may be looking for is the &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript" rel="nofollow" target="_blank"&gt;revealing module pattern&lt;/A&gt;&lt;SPAN&gt;, which Dojo modules can implement very effectively.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So for example, something that may seem quite Java'ish.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;define(['dojo/_base/declare'], function(declare) { &amp;nbsp; var _myValue; &amp;nbsp;&amp;nbsp; &amp;nbsp; return declare([], { &amp;nbsp;&amp;nbsp;&amp;nbsp; constructor: function() { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _myValue = 1; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, &amp;nbsp;&amp;nbsp;&amp;nbsp; setMyValue: function(value) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (_myValue !== value) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _myValue = value; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp;&amp;nbsp; }, &amp;nbsp;&amp;nbsp;&amp;nbsp; getMyValue: function() { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return _myValue; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp; }); });&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So now, you have a variable _myValue that is protected inside the declared module and inaccessible outside this module, since it is scoped in the define method. You could add any checks/transformations as required in the getter/setters and feel confident that the _myValue cannot be changed unless it's through the setter.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Mar 2014 14:28:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-declare-amp-amp-amp-private-instance-members/m-p/698358#M65037</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2014-03-03T14:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: dojo declare &amp; private instance members</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-declare-amp-amp-amp-private-instance-members/m-p/698359#M65038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That explanation helps a lot.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Mar 2014 15:20:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-declare-amp-amp-amp-private-instance-members/m-p/698359#M65038</guid>
      <dc:creator>BrianRassier</dc:creator>
      <dc:date>2014-03-03T15:20:20Z</dc:date>
    </item>
  </channel>
</rss>

