Here’s the code in CoffeeScript:
class this.User extends Backbone.Model
initialize: ->
@access_token
@cur_video_id_playing
@logged_in = 0
@username
this.bind "change:username", () -> alert this.get(username)
this.user = new User;
When I’m in the developer console and call
user.username = "newname"
The alert doesn’t trigger.
What am I doing wrong?
Thanks!
You’ve got to use
Model::set:Or, using an object literal:
The username will actually be stored in
user.attributes.username. In your change listener, you should access the username usingModel::get; something like: