我有三個支柱的看法是這樣的:骨幹觀的繼承到孫級
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