This is not very different for classes. The body of a constructor function simply becomes the body of a constructor :
class MyClass { constructor() { var privateFunction = function () { return 0; }; this.publicFunction = function () { return 1; }; } }
Of course, publicFunction can also be a real method, as in your example, if it does not need access to privateFunction .
I do not particularly recommend this (I am against pseudo-private properties for various reasons), but that would be the easiest translation of your code.
source share