node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



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"
class A
  this.toString = ->
  # after mixed in, use this method to detect who behaves like who (duck typing) 
  this.isA = (obj) ->
    return if obj? then Boolean(obj["__is#{@}"]) else false
  a: ->
    console.log "[A.a] called"
class B
  b: ->
    console.log "[B.b] called"
class C
  @acts_as A,B
  c: ->
    console.log "[C.c] called"
= new C
console.dir i
console.log "i.a():#{i.a()}"
console.log "i.b():#{i.b()}"
console.log "i.c():#{i.c()}"
console.log "i behave like A? : #{A.isA(i)}"


This little module is inspired by:

  1. discussion on coffee-script mixin:

  2. acts_as in the Ruby's way: