Skip to content

Instantly share code, notes, and snippets.

@area73
Created March 26, 2019 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save area73/b2f7a1372855e683acc631591e890561 to your computer and use it in GitHub Desktop.
Save area73/b2f7a1372855e683acc631591e890561 to your computer and use it in GitHub Desktop.
Private methods in ES6
// USING SYMBOL
'use strict'
const _resetTable = Symbol('resetTable');
const _replaceTable = Symbol('replaceTable');
;
class Rejs {
constructor() {
}
// public
createTable(tableName) {
this[_resetTable](tableName)
}
// private
[_replaceTable](tableName, data) {
// wadus wadus
}
}
// USING WeekMaps
const _counter = new WeakMap();
const _action = new WeakMap();
class Countdown {
constructor(counter, action) {
_counter.set(this, counter);
_action.set(this, action);
}
dec() {
let counter = _counter.get(this);
if (counter < 1) return;
counter--;
_counter.set(this, counter);
if (counter === 0) {
_action.get(this)();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment