我在这里有一个基类:
function Screen(src) {
this.src = src;
}
Screen.prototype.html = function(collapsed) {
return $.ajax({
async : false,
url : this.src + "?collapsed=" + collapsed,
}).responseText;
};
然后我尝试对它进行子类化:
function TitleScreen() {
Screen.call(this, "title.php");
};
TitleScreen.prototype = Object.create(Screen.prototype);
TitleScreen.prototype.constructor = TitleScreen;
TitleScreen.prototype.parent = Screen.prototype;
但是,当我这样做并尝试使用 TitleScreen 对象时,它设置了 src 属性,但未定义 html 函数!我还尝试在构造函数中设置 html 函数,如下所示:
function Screen(src) {
this.src = src;
this.html = function(collapsed) {
return $.ajax({
async : false,
url : this.src + "?collapsed=" + collapsed,
}).responseText;
};
}
但这也没有用。我做错了什么可能导致普通的旧属性起作用但不起作用?