strict classes
Javascript is known of no having privates and no members (are plain functions).
Recently a new proposal has raised for the standard to have privates using the #
symbol.
This package creates a new method of creating class constructors that have methods and everything else is private.
; { thisname = name; this#sound = sound; } { return thisname; } { return this#sound; } const animal = 'yogi' 'nyam';// animal.#sound throwslet getName getSound = animal;// getName() throws// getSound() throws const StrictAnimal = ;const strictAnimal = 'yogi' 'nyam';// animal.#sound throwsgetName getSound = animal;
Accessing the public this
There are two this, the private this, only visible by the class, and the public this, visible by anyone.
The class itself can ask for the public this by calling getPublicThis
.
; { return thisname; } { thisname = name; return ; } const animal = ;;;