Backbone.js - 错误加载脚本

wwl*_*wli 1 javascript backbone.js

我的html标题中包含了jquery.js,backbone.js,underscore.js(我可以在浏览器中看到这些文件)

 <script type='text/javascript'>
    (function($){
     var Student= Backbone.Model.extend({
          initialize: function(){
              console.log("studentis createrd");
          }
      });

        var students= Backbone.Collection.extend({
            model: Student
        });  

        console.log(students.models);
    })(jQuery);
</script>
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息 在此输入图像描述

更新:html标头

<script src="/static/js/jquery.js" type="text/javascript"> </script>
<script src="/static/js/backbone.js" type="text/javascript"></script>
 <script src="/static/js/underscore.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

Sus*_* -- 7

首先,您需要确保正确加载Backbone -

订单应该是

   ---> jQuery
   ---> underscore
   ---> backbone
Run Code Online (Sandbox Code Playgroud)

接下来需要创建集合新实例

在创建模型或集合的实例之前,您无法直接在模型或集合上操作.

(function ($) {
    var Student = Backbone.Model.extend({  // Created a Student model
        initialize: function () {
            console.log("studentis createrd");
        }
    });

    var Students = Backbone.Collection.extend({  // Create a Students collection
        model: Student
    });

    var student = new Student(); // Create a instance of Student model

    var students = new Students(); // New instance of Students collection
    students.add(student);   // Add a model to the collection

    console.log(students.models);
})(jQuery);
Run Code Online (Sandbox Code Playgroud)

检查小提琴