我有三个这样的主干视图:
ParentView = Backbone.View.extend({
addUsers : function()
{
console.log("Parent's Add User");
},
addProject : function()
{
console.log("Parent's Add Project");
}
});
ChildView = ParentView.extend({
addProject : function()
{
var self = this;
console.log("Child's add Project");
self.constructor.__super__.addProject.apply(self);
}
});
GrandChildView = ChildView.extend({
addItem : function()
{
var self = this;
self.addProject();
},
addUsers : function()
{
var self = this;
console.log("Grand Child's Add users");
self.constructor.__super__.addUsers.apply(self);
}
});
var vChild = new ChildView();
vChild.addProject(); // works fine, by calling it own and parent's functions.
var vGrandChild = new GrandChildView();
vGrandChild.addUsers(); // This throws Maximum call stack size exceeded error,
当我创建 GrandChildView 的新实例然后调用它的 addUsers 方法时,它会抛出超出的最大堆栈大小,我猜这是因为它一直在调用自己。但无法弄清楚。原因似乎是调用 super 的方法。
谢谢你。