尝试创建Backbone.js视图子类时出错

时间:2011-12-12 15:30:27

标签: javascript ruby-on-rails-3.1 backbone.js coffeescript

我有以下的backbone.js视图:

class MyApplication.Views.Cake extends Backbone.View
    tagName: 'li'
    className: 'cake'

和尝试的子类

class MyApplication.Views.AwesomeCake extends MyApplication.Views.Cake

但是在javascript控制台中,子类上会抛出以下错误:

Uncaught TypeError: Cannot read property 'prototype' of undefined

1 个答案:

答案 0 :(得分:4)

我发现我的问题是Rails 3.1和资产管道的问题。由于sprockets按字母顺序加载javascript文件(因为awesome_cake出现在cake之前),我需要超文件文件。

#= require ./cake
class MyApplication.Views.AwesomeCake extends MyApplication.Views.Cake

有问题的解决方案: Backbone.js - Coffeescript extends