Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

acts-as

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acts-as

a simple class-level mixin module for coffee-script, which provides a handy "composition over inheritance" way for writting complex programs

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

#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"

class A

  this.toString = ->
    'ClassA'

  # 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"
    "AAA"

class B
  b: ->
    console.log "[B.b] called"
    "BBB"

class C
  @acts_as A,B
  c: ->
    console.log "[C.c] called"
    "CCC"

i = 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)}"

Reference

This little module is inspired by:

  1. discussion on coffee-script mixin: https://github.com/jashkenas/coffee-script/issues/452#issuecomment-3699651

  2. acts_as in the Ruby's way: http://yehudakatz.com/2009/11/12/better-ruby-idioms/

Keywords

FAQs

Package last updated on 12 Jun 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc