未定义变量- backbone.js

bhmjp9jg  于 2022-11-10  发布在  其他
关注(0)|答案(2)|浏览(136)

我对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方法,该如何实现呢?

x33g5p2x

x33g5p2x1#

这是一个语法错误。您不能只在对象内部定义变量。

window.dog = Backbone.Collection.extend({
	model : animal,
	initialize : function(){
	 _.bindAll(this);
	},
    // change to this 
    dog :  new dog()
});
mspsb9vt

mspsb9vt2#

正如Satish已经建议的那样,将dog属性设置为扩展对象将解决该问题。还要确保dog在FILE A中从FILE B可用。您可以尝试以下操作:
第一个

相关问题