Skip to content

Instantly share code, notes, and snippets.

@ravicious
Created June 4, 2015 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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