JS Class Access Features ES10 ES2019 Private class features Class Fields The secret to remembering how the hash works is you can t use it outside of the class Any attempt to use the member with a hash outside the class will be rejected by the compiler hence keep hashes in classes Using the HASH to add permission control private class Test myprivateval 1 mypublicval 2 myprivatemethod function return 3 mypublicmethod function return this myprivatemethod 1 let t new Test console log t myprivateval fails returns undefined console log t mypublicval console log t mypublicmethod console log t myprivatemethod error can t be accessed Add in some inheritence using the extends keyword class Test myprivateval 1 mypublicval 2 myprivatemethod function return 3 mypublicmethod function return this myprivatemethod 1 class TestChild extends Test publicchildmethod1 function return this mypublicmethod fail private doesn t fall to children publicchildmethod2 function return this mypublicval privatechildmethod function return 1 let t new TestChild console log t myprivateval returns undefined fails console log t mypublicval console log t publicchildmethod1 fails console log t publicchildmethod2 console log t privatechildmethod error can t be accessed
ing the extends keyword class Test myprivateval 1 mypublicval 2 myprivatemethod function return 3 mypublicmethod function return this myprivatemethod 1 class TestChild extends Test publicchildmethod1 function return this mypublicmethod fail private doesn t fall to children publicchildmethod2 function return this mypublicval privatechildmethod function return 1 let t new TestChild console log t myprivateval returns undefined fails console log t mypublicval console log t publicchildmethod1 fails console log t publicchildmethod2 console log t privatechildmethod error can t be accessed