Created
June 4, 2015 18:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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