node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org ยป


Use with browserify or AMD loader:

Record = require 'backbone.record'

it generates getters and setters for you:

class User extends Record
  @define 'username', 'email'

user = new User

# calls user.set('username', 'andreypopp')
# and so fires 'change:username' events
user.username = 'andreypopp'

# calls user.get('username')

# throws an error cause 'name' attribute wasn't defined = 'Andrey Popp'

and provides you with smart .parse() implementation which respects nested models and collections:

class Address extends Record
  @define 'city', 'street'

class User extends Record
    timestamp: Date
    address: Address

user = new User
  timestamp: '2012-01-01'
  address: {city: 'Moscow', street: 'Tverskaya'}

assert user.timestamp instanceof Date
assert user.address instanceof Address