[英]Keep getting undefined
I am working on javascript backbone project. 我正在研究javascript骨干项目。 I declared a global object like follow
我声明了以下全局对象
window.App = { Vent: _.extend({}, Backbone.Events) }
I did above in initialize
function like following 我在上面的
initialize
函数中做了如下
initialize: function () {
window.App = { Vent: _.extend({}, Backbone.Events), hello: 'yes' };
console.log(App); // This is ONE. see explanation below for ONE
console.log(App.Vent); // This is TWO. see explanation below
}
ONE This log line shows following 一个此日志行显示以下内容
function (){return parent.apply(this,arguments)} app.js:22
TWO 二
This log line show 此日志行显示
undefined
Also if I do console.log(App.hello)
it still says undefined
另外如果我做
console.log(App.hello)
它仍然说undefined
Please help me what am I doing wrong in this code? 请帮助我,我在这段代码中做错了什么?
Update 更新资料
Here is all the related code to my problem. 这是与我的问题有关的所有代码。 I am using requirejs and backbone
我正在使用requirejs和骨干
here is my main.js 这是我的main.js
require(['domReady', 'views/app', 'jqm'], function (domReady, AppView) {
domReady(function () {
window.App = { Vent: _.extend({}, Backbone.Events) };
new AppView();
});
});
here is views/app.js
file 这是
views/app.js
文件
define(['backbone', 'views/home/homes', 'collections/homes'], function (Backbone, HomesView, HomesCollection ) {
var App = Backbone.View.extend({
el: 'div#page',
events: {
'swipeleft': 'nextView',
'swiperight': 'preView'
},
nextView: function (e) {
console.log(App.Vent);
//App.Vent.trigger('changeView', { direction: 'next' });
},
preView: function (e) {
console.log(App.Vent);
//App.Vent.trigger('changeView', { direction: 'prev' });
}
});
return App;
});
What I am doing in this file is when user swipes left or right
then it calls nextView and preView functions. 我在此文件中执行的操作是当用户
swipes left or right
时,它将调用nextView和preView函数。 In these functions I want to trigger and Event which I listen to them in another view. 在这些函数中,我要触发事件,然后在另一个视图中监听它们。 But right now I want to console it.
但是现在我要进行控制台。 But it says
undefined
但它说
undefined
Try to change: 尝试更改:
var App = Backbone.View.extend({
to something else. 去别的东西。 Like this:
像这样:
var iApp = Backbone.View.extend({
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.