7

我正在尝试使用 Backbone.js,只是试图让消息在我的控制台屏幕上弹出。但是,每次我这样做时,都会不断出现错误(如下所述)

Uncaught TypeError: Expecting a function in instanceof check, but got [object Object] backbone.js:1032
_.extend.setElement backbone.js:1032
_.extend._ensureElement backbone.js:1104
Backbone.View backbone.js:986
child backbone.js:1531
(anonymous function) pageLoader.js:19
(anonymous function)

这是JavaScript文件

(function ($){

window.PageLoader = Backbone.View.extend({
  el: $("section"),
  events: {
   "": "initialization",
    "click #aboutUs" : "aboutUs",
  },

  initialization: function(){
    console.log('pageLoader.js initialized\nHome page rendered');
  },

  aboutUs:function(){
    console.log('About us page rendered.');
  } 
});

var pageLoader = new PageLoader();
//pageLoader.initialization();
//pageLoader.aboutUs();

})(jQuery);

这里也是HTML

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <meta />
    <meta />
    <title>Bus tours and tows</title>
  </head>
  <body>
  <div id="centerWrapper">
    <header>
      <h1>So and so Bus tours and tows</h1>
    <header/>
    <nav>
      <ul>
        <li><a href="">Home</a></li>
        <li><a href="#aboutUs">About us</a></li>
        <li><a href="">Tours</a></li>
        <li><a href="">Tows</a></li>
        <li><a href="">Schedule</a></li>
        <li><a href="">Contact</a></li>
      </ul>
    </nav>
    <section></section>
    <footer> &#169; Of So and so bus tours and tows. <br />
      <i>Questions regarding the construction of the website, please email</i>
      <a href="mailto: joshua.villahermosa@joshvee.com">Web Master</a>
    </footer>
    <div id="jsFilesAndDepend">
       <!-- -->
       <!-- Filese that are dependant-->
       <script src="js/dependencies/underscore.js"></script>
       <script src="js/dependencies/backbone.js"></script>
       <script src="js/dependencies/jquery-1.10.1.js"></script>
       <script src="js/pageLoader.js"></script>
       <script src=""></script>
       <script src=""></script>
    </div>
  </div>
  </body>
</html>

我是 Backbone.JS 的新手。感谢您的帮助。

4

1 回答 1

9

您需要在主干之前加载 jQuery,

  <script src="js/dependencies/underscore.js"></script>
  <script src="js/dependencies/jquery-1.10.1.js"></script>
  <script src="js/dependencies/backbone.js"></script>

您也不能定义空的事件键值对,

 events: {
 //   "": "initialization", <- this is invalid.
  "click #aboutUs" : "aboutUs",
 },
于 2013-06-26T20:23:43.320 回答