【发布时间】:2011-09-13 07:57:06
【问题描述】:
class TheModel extends Backbone.Model
foo:
#bar
Entity = new TheModel(#pass in attributes)
然后我可以扩展实体并维护模型属性/状态吗?
class User extends Entity
foo:
super
#more
编辑:
class Entity extends Backbone.Model
initialize: (options) ->
@_events options
_events: (options) ->
entity.bind 'foo'
class Entity1 extends Entity
_events: (options) ->
super options
entity.bind 'bar'
class Entity2 extends Entity
_events: (options) ->
super options
entity.bind 'baz'
#a new entity arrives, we don't know if he is type one or two yet so he is...
entity = new Entity
#now we find out he is type 2
entity = new Entity2(entity.attributes)
【问题讨论】: