@snek/private

Completely unenumerable symbols that you can use to store private data on any object. Only those with access to the symbol can access the data.

Usage no npm install needed!

<script type="module">
  import snekPrivate from 'https://cdn.skypack.dev/@snek/private';
</script>

README

@snek/private

Completely unenumerable symbols that you can use to store private data on any object. Only those with access to the symbol can access the data.

const PS = require('@snek/private');

const mySecret = PS('mySecret');
class MyClass {
  constructor(x) {
    this[mySecret] = x;
  }

  add(y) {
    return this[mySecret] + y;
  }
}

const obj = {};
obj[mySecret] = 5;