Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you're misunderstanding the overall concept of the module pattern, when you need to have a global static variable shared between all your instances then you can declare or initialize your variable with the keyword "var" just before the return statement.</p> <p><strong>Assume that whenever you change those variables all your instances will be impacted by the change</strong>.</p> <pre><code>var slideMenu=function(){ // Declare or initialize your private static variables here var speed, startWidth, time; return { // Public part of your object slide:function(s,passChange){ //To access your variable speed = 20; ... </code></pre> <p>On the other hand if you want to keep variable safe from the global scope, you have to put your variable into the object returned by your function, this is a reliable way to provide <strong>unique per instance properties</strong>.</p> <pre><code>var slideMenu=function(){ // Declare or initialize your private static variables here var speed, startWidth, time; return { // Public part of your object // Declare internal or public properties here menuId : 0, liID : 0, menuLen : 0, ... slide:function(s,passChange){ //To access your private static variable inside functions speed = 20; // To access your public/internal properties this.menuId = s; // for example ;) } </code></pre> <p><strong>To conclude</strong></p> <p>Sometimes to help distinguish between internal / public properties some folks writes a leading underscore on their internal properties (note that properties will still remain accessible from the outside).</p> <p>Hope it helps, good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload