Jos*_*h V 7 javascript uncaught-exception backbone.js underscore.js
我正在试验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)
Run Code Online (Sandbox Code Playgroud)
这是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);
Run Code Online (Sandbox Code Playgroud)
这里还有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> © 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>
Run Code Online (Sandbox Code Playgroud)
我是Backbone.JS的新手.谢谢你的帮忙.
你需要在骨干之前加载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>
Run Code Online (Sandbox Code Playgroud)
您也无法定义空事件键值对,
events: {
// "": "initialization", <- this is invalid.
"click #aboutUs" : "aboutUs",
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7084 次 |
| 最近记录: |