defineClass - simple yet powerful OOP and AOP for JavaScript
Besides classic OOP defineClass has:
- Traits from Scala
- Decorators from Python
- Nested class overriding
- Proxy class and trait generation.
Quick start
This is a quick start. Detailed explanations are in the wiki.
Defining a class
// define a classvar Device = ;
Defining a subclass
// define a subclassvar Phone = ;
Applying a trait
// define a traitvar TurnOnWithSplash = defineClass; // apply a trait to a classvar Smartphone = ;var phone = 1000 "120-1010";phone;// Output:// Turning on...// Playing sound...// Showing splash...
You can use the same trait in different class hierarchies. Read more about traits here.
Decorating
// define a decorator that adds function call loggingvar logging = defineClass; // apply the decorator to all methodsvar Phone = ; var phone = ;phone;// Output:// Entering dial// Dialing to 120-0000// Exiting dial
Read more about decorators here.
Installation
$ npm install defineClass