“Uncaught TypeError: undefined is not a function” initializing Backbone collection

后端 未结 2 1773
深忆病人
深忆病人 2021-02-14 05:16

I have a Backbone collection something like the following:

var FooCollection = Backbone.Collection.extend({
    model:Foo,

    initialize: function (attributes,         


        
相关标签:
2条回答
  • 2021-02-14 05:52

    I was experiencing the same problem. My problem was I had included my Model script after Collection Script:

    <script src="scripts/collections/Classes.js"></script>
    <script src="scripts/models/Class.js"></script>
    

    To fix it I just had to move the Class.js up above Classes.js:

    <script src="scripts/models/Class.js"></script>
    <script src="scripts/collections/Classes.js"></script>
    

    Cheers

    0 讨论(0)
  • 2021-02-14 05:59

    In my actual code Foo was declared after FooCollection. Didn't realize that Javascript doesn't support forward declarations. [headdesk]

    0 讨论(0)
提交回复
热议问题