coool
coool

Reputation: 8297

how to avoid my method overriding existing backbone view methods

would adding event methods override the existing backbone view methods. I am using layout manager which add some more methods..I wanted to avoid override the methods..what is the best way for naming my method

$ ->
    class Overlay extends Backbone.View
        events:
            'click .close': 'close'

        close: (e)=>
            @remove()

The close Method will be added to the view..if there is a close method in backbone view it will be overridden...??

Upvotes: 0

Views: 94

Answers (1)

Vic
Vic

Reputation: 8981

yes, same reason how implementing your own render function will overwrite backbone's default render function.

You can always prefix your methods with underscore if you are worried that you might overwrite some default functions.

Example:

'click .close': '_close'

It's a common practice to prefix private methods with underscore anyways. That or just give it a more specific name... You can also define the function directly:

'click .close': function(){
    ...
}

Upvotes: 0

Related Questions