Skip to content

Instantly share code, notes, and snippets.

@k33g
Created November 11, 2011 20:18
Show Gist options
  • Save k33g/1359112 to your computer and use it in GitHub Desktop.
Save k33g/1359112 to your computer and use it in GitHub Desktop.
kind of annotations with CoffeeScript
__ = (from,name,member,annotation)->
if not from.annotations then from.annotations = {}
if not from.annotations[name] then from.annotations[name] = {}
from.annotations[name][member] = annotation
class Human
__ @, "Model", "constructor", "localStorage"
__ @, "gui", "name", "name:input type = text"
__ @, "gui", "weight", "weight:input type = text"
__ @, "gui", "fields", {name : 'string', weight : 'integer'}
constructor: (name, weight) ->
@name = name
@weight = weight
__ @, "service", "sayHello", "url://..."
sayHello:->
console.log "Hello #{@name}"
__ @, "service", "weight", "http://www.k33g.org?weight"
weight:->
console.log weight
console.log '-----------------------------------------------'
console.log Human.annotations.Model.constructor
console.log Human.annotations["service"]["sayHello"]
console.log Human.annotations.service.weight
console.log Human.annotations.gui.fields
console.log '-----------------------------------------------'
for m of Human.annotations
console.log Human.annotations[m]
console.log '-----------------------------------------------'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment