声明骨干扩展类在另一个文件 - 的CoffeeScript [英] Declaring backbone extension class in another file - coffeescript

查看:86
本文介绍了声明骨干扩展类在另一个文件 - 的CoffeeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下类扩展Backbone.View,我想我所有的骨干意见,从这个类继承:

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:

基本视点未定义

我怎么能保持在一个不同的文件基本视点并用它来延长我的自定义视图?

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

推荐答案

将这个在 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

这篇关于声明骨干扩展类在另一个文件 - 的CoffeeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆