class RedGuy
constructor : (@name) ->
@nameElem = $ @name
@nameElem.css color : red
class WideRedGuy extends RedGuy
constructor : ->
@nameElem.css width : 900
jeff = new WideRedGuy '#jeff'
I would like #jeff to be both red and wide, but I always get this.name is undefined. How can I extend the constructor (append?) so that I have access to the properties of the original object?
You need to explicitly call
superfor this to work. CallingsuperinWideRedGuywill callRedGuy‘s constructor, after which@nameElemwill be properly defined. For a more in-depth explanation, you should consult coffeescript’s documentation on the matter.