Created
May 12, 2011 00:48
-
-
Save jmoyers/967717 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
if not window? | |
inherits = require('util').inherits | |
EventEmitter = require('events').EventEmitter | |
_ = require('underscore') | |
extend = _.extend | |
keys = Object.keys | |
class Model extends EventEmitter | |
constructor: (attribs) -> | |
attribs |= {} | |
@attribs = extend(@attribs, attribs) | |
@track (keys(@attribs)) | |
track: (keys) -> | |
if not typeof keys == Array | |
keys = [] | |
for key in keys | |
@__defineGetter__ key, -> | |
@get(key) | |
@__defineSetter__ key, -> | |
@set(key) | |
set: (key, val, quiet) -> | |
@attribs[key] = val | |
if not quiet | |
@emit 'change', {key:val} | |
get: (key) -> | |
@attribs[key] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment