Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document private vars #55

Open
bcomnes opened this issue Sep 3, 2017 · 1 comment
Open

Document private vars #55

bcomnes opened this issue Sep 3, 2017 · 1 comment

Comments

@bcomnes
Copy link
Contributor

bcomnes commented Sep 3, 2017

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)
@bates64
Copy link

bates64 commented Dec 23, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants