骨干,xxx 不是构造函数



我正在尝试使用骨干,木偶和咖啡脚本制作多页应用程序。

应用程序/主页.咖啡

define [
    'App'
    './index/index'
],
(App, HomeIndex) ->
    class HomeApp extends App
        constructor : () ->
            super
            console.log typeof HomeIndex #return object
            @homeIndex = new HomeIndex() #TypeError: HomeIndex is not a constructor
            @initialize()
        initialize: ->
            console.log 'app initialize'
            App.contentArea.show homeIndex
apps/home/index

/index.coffee

define [],
()->
    class HomeIndex extends Backbone.Marionette.Layout
        template: '<div>Hello, Backbone! </div>'
        constructor: () ->
            console.log '!'
        initialize: (options) ->
            @template = _.template @template
            console.log "Home Index initialized"
        render: () =>
            @$el.html @template

我无法初始化HomeIndex,有人知道我做错了什么吗?

请指教

更新:

 define [
        'App'
        'apps/home/index/index'
    ],

但仍然类型返回 HomeIndex 返回对象,而不是函数。

首先,当您遇到此类问题时,请检查 Requirejs 加载的文件。您可能已经看到./index/index要么不是您所期望的,要么根本没有加载。

基本上,AMD不支持相对链接。仅相对于baseUrl的链接。

最新更新