0
要開始這個問題有點不同於大多數SO問題,這裏的代碼工作位:使用JS MVC控制器作爲存儲值,作爲第一類對象
thingsToLoad: [{
id: 'thing1',
controller: function(el) {
el.my_project_controller1({});
}
}, {
id: 'thing2',
controller: function(el) {
el.my_project_controller2({});
}
}],
init: function() {
var self = this;
$.each(self.thingsToLoad, function(index, tool) {
tool.controller(self.find('#'+tool.id));
});
}
搞清楚,因爲函數是一類對象,我應該能夠做到這一點:
thingsToLoad: [{
id: 'thing1',
controller: my_project_controller1
}, {
id: 'thing2',
controller: my_project_controller2
}],
init: function() {
var self = this;
$.each(self.thingsToLoad, function(index, tool) {
self.find('#'+tool.id).tool.controller({});
});
}
然而,它將在thingsToLoad
停在一個控制器的第一個聲明。錯誤是:Uncaught ReferenceError: my_project_controller1 is not defined
爲什麼會發生這種情況?我無法弄清楚。
這聽起來像是你對第一課class_意味着什麼感到困惑。 – Mathletics