Skip to content

Instantly share code, notes, and snippets.

View ticking-clock's full-sized avatar

Alan Kendall ticking-clock

View GitHub Profile
@ticking-clock
ticking-clock / backbone-computed.mixin.coffee
Created June 9, 2013 22:51
A mixin that adds computed properties to Backbone.Model. Works, but alters get() in a way that mixins should not.
Backbone.Model.mixin ||= (mixin) ->
_.extend(@prototype, mixin)
Backbone.Mixins ||= {}
Backbone.Mixins.ComputedAttributes =
initialize: ->
return if _.isUndefined(@computed)
for attr, dependencies of @computed
@bind "change:#{attr}", () =>