nanocomponent icon indicating copy to clipboard operation
nanocomponent copied to clipboard

Document private vars

Open bcomnes opened this issue 8 years ago • 1 comments

I don't know of a good way to protect private vars from being overwritten. I know @toddself accidentally ran into the situation where he overwrote a private var. Perhaps we could add a list of private vars not to overwrite.

this._hasWindow = typeof window !== 'undefined'
this._id = null // represents the id of the root node
this._ncID = null // internal nanocomponent id
this._proxy = null
this._loaded = false // Used to debounce on-load when child-reordering
this._rootNodeName = null
this._name = name || 'nanocomponent'
this._arguments = []

this._handleLoad = this._handleLoad.bind(this)
this._handleUnload = this._handleUnload.bind(this)

bcomnes avatar Sep 03 '17 14:09 bcomnes

A good way to do private vars is to feature-check for ES6 Symbols and use a fallback if the browser does not support them. e.g.

Nanocomponent.id = Symbol in window ? Symbol() : '_id'

class Nanocomponent {
  constructor() {
    this[Nanocomponent.id] = 1234
  }
}

You can even prefix the non-symbol with a random number for added anti-collision measures.

bates64 avatar Dec 23 '17 18:12 bates64