我对backbone.js很陌生,我正在尝试访问从文件B到文件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方法,该如何实现呢?
2条答案
按热度按时间x33g5p2x1#
这是一个语法错误。您不能只在对象内部定义变量。
mspsb9vt2#
正如Satish已经建议的那样,将
dog
属性设置为扩展对象将解决该问题。还要确保dog
在FILE A中从FILE B可用。您可以尝试以下操作:第一个