Created
September 12, 2012 07:14
-
-
Save 525c1e21-bd67-4735-ac99-b4b0e5262290/3704888 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{EventEmitter} = require 'events' | |
uuid = require 'node-uuid' | |
module.exports = class Model extends EventEmitter | |
constructor: -> | |
super | |
@property: (key, descriptor = {}) -> | |
@properties ?= {} | |
@properties[key] = descriptor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert = require 'assert' | |
Model = require '../lib/model' | |
model = new Model | |
assert.ok model | |
console.log 'defining foo' | |
class Foo extends Model | |
@property 'id', type: String | |
console.log 'defining bar' | |
class Bar extends Foo | |
@property 'anumber', type: Number | |
@property 'aregexp', type: RegExp | |
console.log '\n' | |
console.log 'making foo' | |
foo = new Foo | |
console.log 'making bar' | |
bar = new Bar | |
console.log '\n' | |
console.log foo.constructor.name | |
console.log foo.constructor # .properties | |
console.log bar.constructor.name | |
console.log bar.constructor # .properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ava:feisty pyro$ coffee test/model.coffee | |
defining foo | |
defining bar | |
making foo | |
making bar | |
Foo | |
{ [Function: Foo] | |
__super__: { constructor: { [Function: Model] __super__: [Object], property: [Function] } }, | |
property: [Function], | |
properties: | |
{ id: { type: [Function: String] }, | |
anumber: { type: [Function: Number] }, | |
aregexp: { type: [Object] } } } | |
Bar | |
{ [Function: Bar] | |
__super__: | |
{ constructor: | |
{ [Function: Foo] | |
__super__: [Object], | |
property: [Function], | |
properties: [Object] } }, | |
property: [Function], | |
properties: | |
{ id: { type: [Function: String] }, | |
anumber: { type: [Function: Number] }, | |
aregexp: { type: [Object] } } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment