Declaring backbone extension class in another file - coffeescript

烂漫一生 提交于 2019-12-24 13:44:18

问题


I have the following class that extends Backbone.View, I want all my backbone views to inherit from this class:

class BaseView
  constructor: (options) ->
    @bindings = []
    Backbone.View.apply(@, [options])

  _.extend(BaseView.prototype, Backbone.View.prototype, {
  #etc. tec.

BaseView.extend = Backbone.View.extend

I can then extend my own view like this:

class BusinessUnitsView extends BaseView
  initialize: (options) ->

This all works fine if they are in the same file but if I separate BaseView into a different file, I get an error message:

BaseView is undefined

How can I keep the BaseView in a different file and use it to extend my custom views?


回答1:


Put this under BaseView.extend = Backbone.View.extend

@.BaseView = BaseView

it makes your BaseView global accessible

I always declare my classes like this and it works great

class BaseView extends Backbone.View

@.BaseView = BaseView


来源:https://stackoverflow.com/questions/8081438/declaring-backbone-extension-class-in-another-file-coffeescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!