chaplinjs/chaplin

CoffeeScript class inheritance

Closed this issue · 1 comments

Hi,

I have a weird behaviour and I was wondering if you guys knew what was causing it. I think it has to do with CS and class inheritance, but it looks weird.

This is my base View. I need to render all views on a certain event, so I thought that the base was a good place to do so:

class View extends Chaplin.View
    initialize: ->
        @subscribeEvent 'event', @doSomething
        super

    doSomething: ->
         # somethings and then:
        @render()

Then I have a view:

class MyView extends View
    initialize: ->
        @delegate 'submit', '.client-invitation-form', @sendInvitation
        super

    sendInvitation: (event) ->
        console.log 'sendInvitation'

So everything works fine, it re renders the view when the event is triggered. BUT the delegate is now broken.

If I change the code to doSomething to:

    doSomething: ->
         # somethings and then:
        @r?()

And add a r method to my MyView:

r: () -> @render()

I'm back in business! I guess there is some scope issue and CS inheritance shit going on here but can't figure out what it is. Any idea? Thanks!

I apology for the trouble, there were a fuck in my code...