Skip to content

Instantly share code, notes, and snippets.

@ravicious
Created June 4, 2015 18:33
Show Gist options
  • Save ravicious/5412eebf8a1934ec7886 to your computer and use it in GitHub Desktop.
Save ravicious/5412eebf8a1934ec7886 to your computer and use it in GitHub Desktop.
Private function example based on raganwald's "Classes are Expressions" http://raganwald.com/2015/06/04/classes-are-expressions.html Discussion: https://news.ycombinator.com/item?id=9660908
let Person = (() = > {
let firstNameProperty = Symbol('firstName'),
lastNameProperty = Symbol('lastName'),
renameProperty = Symbol('rename');
let rename = function(first, last) {
this[firstNameProperty] = first;
this[lastNameProperty] = last;
return this;
}
return class Person {
constructor (first, last) {
this[renameProperty] = rename.bind(this);
this[renameProperty](first, last);
}
fullName () {
return this[firstNameProperty] + " " + this[lastNameProperty];
}
};
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment