所以我正在使用 Backbone/CoffeeScript 启动这个新应用程序。我使用的是 Sinatra 的后端,所以我的 Coffeescript 编译器是默认的命令行编译器,它只创建 js 文件。我正在尝试创建一个应用程序,其中有一个其他类继承自的主类。出于某种原因,我遇到了一些错误。这是错误
TypeError: 'undefined' is not an object (evaluating 'n.replace')
TypeError: 'undefined' is not an object (evaluating 'parent.prototype')
TypeError: 'undefined' is not a constructor (evaluating 'new FileApp.UploaderView()')
这是我的基类
class FileApp.Controller extends Backbone.View
template: _.template($('#FileAppTemplate').html())
initialize: (office) ->
@office = office
@render()
render: ->
# Attach view to DOM
$('#fileUploaderApp').append(@$el)
bindViews: (uploaderView, fileViewerView, fileDetailView) ->
@uploaderView = uploaderView
@fileViewerView = fileViewerView
@fileDetailView = fileDetailView
这是一个继承类的例子
class FileApp.FileViewerView extends FileApp.Controller
template: _.template($('#FileViewTemplate').html())
#
# render ->
#
render: ->
@$el.html(@template)
# Append to fileViewer Div
@renderFiles()
#
# createFiles ->
#
renderFiles: ->
下面是我的 .erb 文件如何加载每个项目并实例化应用程序。
<script id="namespacing">
//All backbone classes attach to this variable
var FileApp={};
</script>
<!-- Underscrore/Backbone -->
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script src="/js/fileUploader/libs/file_app_view.js"></script>
<script src="/js/fileUploader/libs/uploader_view.js"></script>
<script src="/js/fileUploader/libs/file_detail_view.js"></script>
<script src="/js/fileUploader/libs/file_model.js"></script>
<script src="/js/fileUploader/libs/file_viewer_view.js"></script>
<script src="/js/fileUploader/libs/file_view.js"></script>
<div id="fileUploaderApp"></div>
<script>
$(document).ready(function(){
var App = new FileApp.Controller();
// # Create Uploader
var uploaderView = new FileApp.UploaderView();
// # Create File Viewer
var fileViewerView = new FileApp.FileViewerView();
// # Create File Detail View
var fileDetailView = new FileApp.FileDetailView();
App.bindViews(uploaderView, fileViewerView, fileDetailView)
});
</script>
如果有人能澄清我的问题,那就太好了。