From a06d7a278f9c7eeca49991fdd17871ee1dadd263 Mon Sep 17 00:00:00 2001 From: Winton Welsh Date: Sun, 24 May 2015 03:13:19 -0700 Subject: [PATCH] Update README --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 872c070..b09809a 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,72 @@ # coffee-mixin - require("coffee-mixin")() + mix = require("coffee-mixin") class A constructor: -> console.log "hello" world: -> console.log "world" class B - @mixin A constructor: -> super() world: -> super() - new B().world() + C = mix A, B - # Outputs: - # hello - # world + new C().world() + # + # hello + # world ## Options -Available options with default values: +We can also automatically wrap all functions to call super before or +after the function is executed. @mixin [Class], - append_super: false, # monkeypatch all functions with super (append) - prepend_super: false, # monkeypatch all functions with super (prepend) - change_super: true # modify existing super + append: false, # append all functions with super + prepend: false, # prepend all functions with super + +## Append Example + + mix = require("coffee-mixin") + + class A + constructor: (str) -> console.log "#{str}lo" + world: (str) -> console.log "#{str}ld" + + class B + + # CoffeeScript does not `return` by default in constructors. + # + constructor: -> return "hel" + world: -> "wor" + + C = mix A, B, append: true + + new C().world() + # + # hello + # world + +## Prepend Example + + mix = require("coffee-mixin") + + class A + + # CoffeeScript does not `return` by default in constructors. + # + constructor: -> return "hel" + world: -> "wor" + + class B + constructor: (str) -> console.log "#{str}lo" + world: (str) -> console.log "#{str}ld" + + C = mix A, B, prepend: true + + new C().world() + # + # hello + # world