Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to have Javascript Object creation pattern with Reusable methods and private properties?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COYou could give each instance a random ID and store its private properties in some kind of data structure. But I would suggest to just forget about privat properties if you use constructor functions. JavaScript is not built for that and any workaround has some disadvantage.
      singulars
    2. CO@FelixKling so lets say we have an auxiliary DS, Like {id1: { list:[3,4],currentIndex:2}, id2: { list:[2,1,4], currentIndex:3} } ... even then in the MyStack.prototype.insert = function(val){ currState = this.auxiliaryDS[this.id]; this.currState.list.push(val).. Again, it is not really private.
      singulars
    3. COYou could define the data store and the constructor function inside a function and only expose the constructor function. The data store would then be private and not be accessible from the outside. Yes, the ID would be accessible, but you could even generate a random property name for this if you wanted to obfuscate it. As I said, JS is not built for this and anything you do will be hacky and/or complex. Proper documentation is more valuable IMO. You can find quite a few related questions here: http://stackoverflow.com/search?q=javascript+private+instance+variables+and+prototype+methods
      singulars
 

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