Javascript 无法扩展主干视图
我可能错过了一些简单的东西或做了一些错误的事情,但我正在尝试这一点,无法让它启动功能Javascript 无法扩展主干视图,javascript,backbone.js,backbone-views,Javascript,Backbone.js,Backbone Views,我可能错过了一些简单的东西或做了一些错误的事情,但我正在尝试这一点,无法让它启动功能 var Home = Backbone.View.extend({ indexAction: function() { console.log('index'); }, render: function() { console.log('render'); } }); Home.indexAction(); 我得到的只是这个错误: 未捕获的Typ
var Home = Backbone.View.extend({
indexAction: function() {
console.log('index');
},
render: function() {
console.log('render');
}
});
Home.indexAction();
我得到的只是这个错误:
未捕获的TypeError:对象函数(){return i.apply(this,arguments)}
没有“indexAction”方法
您创建了视图类型,但未创建实例。 您现在需要实例化类型为
Home
的视图:
var h = new Home();
h.indexAction();
另外,最好将Home重命名为HomeView
,这样您就知道它是一个可以实例化的视图
var HomeView = Backbone.View.extend({
indexAction: function() {
console.log('index');
},
render: function() {
console.log('render');
}
});
var home = new HomeView();