【发布时间】:2011-12-20 02:14:31
【问题描述】:
我在这篇文章http://blog.shinetech.com/2011/07/25/cascading-select-boxes-with-backbone-js/ 中使用backbone.js 进行链接选择,但是在扩展类时出错了。
所以,我有 LocationsView 类:
class Blog.Views.LocationsView extends Backbone.View
events:
"change": "changeSelected"
CountriesView 类:
class Blog.Views.CountriesView extends Blog.Views.LocationsView
setSelectedId: (countryId) ->
CitiesView 类:
class Blog.Views.CitiesView extends Blog.Views.LocationsView
setSelectedId: (cityId) ->
但是当coffeescript代码编译成javascript时,我的双扩展类看起来像:
(function() {
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
cities_view.js:5 Uncaught TypeError: Cannot read property 'prototype' of undefined
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
};
Blog.Views.CitiesView = (function() {
__extends(CitiesView, Blog.Views.LocationsView);
function CitiesView() {
CitiesView.__super__.constructor.apply(this, arguments);
}
CitiesView.prototype.setSelectedId = function(cityId) {};
return CitiesView;
})();
}).call(this);
我得到了错误:
Uncaught TypeError: Cannot read property 'prototype' of undefined cities_view.js:5
那么,问题出在哪里以及如何解决?
【问题讨论】:
-
您能提供完整的堆栈跟踪吗?
标签: javascript ruby-on-rails-3 backbone.js coffeescript