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

发布于 2024-12-20 22:47:08 字数 386 浏览 0 评论 0原文

我有下面的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

I have the backbone.js view below:

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

and the attempted subclass

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

However in the javascript console the following error is thrown on the subclass:

Uncaught TypeError: Cannot read property 'prototype' of undefined

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-12-27 22:47:08

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

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

问题中找到的解决方案:
Backbone.js - Coffeescript 扩展

I found out that my issue was a problem with Rails 3.1 and the asset pipeline. Since sprockets loads the javascript files in alphabetical order (and because awesome_cake comes before cake) I needed to require the superclasses file.

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

Solution found in question:
Backbone.js - Coffeescript extends

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文