javascript - 未定义变量-backbone.js
问题描述
我对backbone.js很陌生,我正在尝试从文件B访问一个var到文件A。目前我已经声明了文件A,如下所示
window.dog = Backbone.Collection.extend({
model : animal,
initialize : function(){
_.bindAll(this);
},
// this is where i am getting an error saying i have not defined dog
var dog= new dog();
})
文件 B:
var dog = function () {
this.eats = {};
this.dance.REQUEST = {};
this.walk.REQUEST.LIST = [];
};
现在我希望从脚本 A 调用方法 eat 我该怎么做?
解决方案
这是一个语法错误。您不能只在对象内定义变量。
window.dog = Backbone.Collection.extend({
model : animal,
initialize : function(){
_.bindAll(this);
},
// change to this
dog : new dog()
});
推荐阅读
- android - Android Room On delete Cascade 不起作用
- google-analytics - 如何找到用户观看视频然后转到另一个网页的速率 (CTR)
- python - 通过多次调用一个函数来显示多个 Matplotlib 图形?
- ios - 创建了一个函数,但在 if 语句中无法快速识别该函数
- linux - Debian 9.4 (stretch) 将 UART4 波特率更改为 9600
- pine-script - 基于随机的回测有困难
- javascript - 您如何使用节点 puppeteer 从页面获取所有链接?
- r - 用列均值替换 NA 值
- javascript - 即使在浏览器关闭后存储此列表数据的最简单方法?
- windows - 为什么 VS Code 在我所有文件的末尾添加了许多空行?