我有三个支柱的看法是这样的:骨干观的继承到孙级
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的方法。
谢谢。
我觉得你在用JS中的'super'玩火。 – fguillen 2012-04-26 18:46:21