backbone-attrs
v0.1.0
Published
ES5 getters/setters for Backbone models
Downloads
5
Maintainers
Readme
backbone-attrs
ES5 getters/setters for Backbone models
Install
npm install backbone-attrs
Use
JavaScript
var attrs = require('backbone-attrs');
var User = Model.extend();
attrs(User, 'username', 'email');
var user = new User;
user.username = 'john'; # -> user.set('username', 'john')
console.log(user.username); # -> user.get('username')
// Can also optionally install() into Model for easier usage
require('backbone-attrs').install();
var User = Model.extend({
attrs: [ 'username', 'email' ]
});
CoffeeScript
attrs = require 'backbone-attrs'
class User extends Model
attrs this, 'username', 'email'
user = new User
user.username = 'john' # -> user.set 'username', 'john'
console.log user.username # -> user.get 'username'
# Can also optionally install into Model.attrs() for easier usage
require('backbone-attrs').install()
class User extends Model
@attrs 'username', 'email'
Test
npm test
License
MIT