Static methods & inheritance in Coffeescript -
Static methods & inheritance in Coffeescript -
i've been reading bit coffeescript's inheritance model , have feeling i'm on fringes of ideological debate don't understand. so, happy find out i'm doing things in wrong way.
basically doing writing set of widgets which, among other things, need handle events on dom elements. thought way go have class method called once, delegate events widget might need. base of operations widget class might have simple click handlers, while subclass might add together mouseover handlers or click handlers.
however, appears i'm not supposed seek , equivalent of calling super()
within static method. there workaround exists, (this.__super__.constructor.methodname()
i've seen lot of suggestions isn't best way i'm trying do. has got insights on how should construction code? maintain using workaround, or set delegation totally different place? can't stick in prototype, since won't have instance phone call method on (or can still phone call method on prototype static context, putting swatchablewidget.prototype.delegateevents()
onload function or something?
here's bit of code illustrate i'm talking about:
class widget @testprop: "themewidget" @delegateevents: -> console.log "delegate generic events" class swatchablewidget extends widget @testprop2 = "swatchwidget" @delegateevents: -> console.log "delegate specific swatchable widget events" this.__super__.constructor.delegateevents() widget.delegateevents() swatchablewidget.delegateevents()
thanks help.
it sounds want different type of inheritance model each inherited function of type ("parent calling") walk inheritance tree , phone call parents same name.
you phone call direct parent functions in each kid manually you've written. float inheritance chain anywhere specify such relationship.
i bind parents delegate phone call in constructor current class function
class="lang-coffee prettyprint-override">delegateparents => #call parent class methods
coffeescript
Comments
Post a Comment