TypeFo
A JavaScript class enhancement tool.
JavaScript is a prototype-based object-oriented language which has a very stupid weak class members protection. All class methods are allowed to be overrided by default and can be rewrited in runtime by prototype manipulation.
TypeFo
is a tool to enhance JS class, it can produce Symbol
for protected methods and protect class prototype by a small function.
Usage
npm install --save typefo
const TypeFo = ; const typefo = 'fn1' 'fn2' 'fn3' true; // every method will lead to a Symbol// just keep typefo instance in a local lexical scope// then use symbols to declare functionsconst PROTECTED = typefosymbols; { // provide instance and class typefoprotect; } { // nobody can access fn1 except this module } { console; } { console; }// module.exports = BaseClass; { console; } { console; } const next = ; // virtual methodsnext; // => fn2, next // immutable public methodsnext; // => fn3
Also TypeFo
can be used in browser.
<!-- dist/typefo.min.js -->