acts-as
a simple class-level mixin module for Node.JS, which provides a handy "composition over inheritance" for writting complex programs
How To Use
require "acts_as" = -> 'ClassA' # after mixed in, use this method to detect who behaves like who (duck typing) = return if obj? then Booleanobj"__is" else false : -> consolelog "[A.a] called" "AAA" : -> consolelog "[B.b] called" "BBB" @acts_as AB : -> consolelog "[C.c] called" "CCC" i = consoledir iconsolelog "i.a():"consolelog "i.b():"consolelog "i.c():"consolelog "i behave like A? : "
Reference
This little module is inspired by:
-
discussion on coffee-script mixin: https://github.com/jashkenas/coffee-script/issues/452#issuecomment-3699651
-
acts_as in the Ruby's way: http://yehudakatz.com/2009/11/12/better-ruby-idioms/