未捕获的TypeError:对象函数(a){return new j(a)}没有方法'has'

时间:2014-03-27 06:44:51

标签: javascript jquery backbone.js

我收到此错误。我是菜鸟,找不到满意的答案。 这是我正在研究的一个例子。我看了很多关于同一类型的问题,但我无法做出任何改变。如果你以描述性的方式回答,那就太好了。

  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <title>hello-backbonejs</title>
  </head>
  <body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9/jquery.min.js"></script>
    <script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
    <script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script>

    <script src="1.js" type="text/javascript"></script>
  </body>
  </html>

//和javascript在这里.....名称“1.js”

(function($){
     var ListView = Backbone.View.extend({
     el: $('body'), // el attache`enter code here`s to existing element

        events: {
      'click button#add': 'addItem'
    },
    initialize: function(){
      _.bindAll(this, 'render', 'addItem'); // every function that uses 'this' as the current object should be in here

      this.counter = 0; // total number of items added thus far
      this.render();
    },

        render: function(){
      $(this.el).append("<button id='add'>Add list item</button>");
      $(this.el).append("<ul></ul>");
    }, addItem: function(){
      this.counter++;
      $('ul', this.el).append("<li>hello world"+this.counter+"</li>");
    }
  });

  var listView = new ListView();
})(jQuery);

1 个答案:

答案 0 :(得分:0)

尝试这样的事情

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.5.0/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script>

原因

  1. 使用jquery 1.9.1而不是1.9
  2. 使用下划线1.5.0