Pooka
npm install pooka
to use this module you have to pass Node.js the --harmony_proxies
V8 flag
% node --v8-options | grep proxies
--harmony_proxies (enable "harmony proxies" (in progress))
Traits reimagined using ES6 Proxies.
Mostly a thought experiment for now, but as Proxies become more battle-tested, it could become a useful pattern.
This implementation lazily constructs implemented Traits.
The last Trait to implement a method is the one that is evaluated.
{ // this will be private since it isn't on the prototype thisn = number } { return true } // these will be public properties { return thisn } { return true } { // these two properties are also private thistype = type thiscontents = } { thiscontents } { return true } { return false } {}// Arguments are curried for instantiationAirplaneAirplaneAirplane {}CarCar // Multiple levels of inheritance {}Amphicar// override Wheels.prototyope.sinksAmphicar {}BikeBike {}SemiSemi car // new Error('Vehicle does not implement fly')