我遇到了原型继承问题,我不知道为什么它不能正常工作。
片段是这样的:
function Field(newKey, val) {
this.key = newKey || "";
this.value = val || "";
}
Field.prototype.isEmpty = function() {
return this.value === undefined || this.value === null || this.value === "";
};
function DoubleField(newKey, val) {
this.base = Field;
this.base(newKey, val);
}
DoubleField.prototype = new Field();
DoubleField.prototype.constructor = DoubleField;
function IntegerField(newKey, val) {
this.base = DoubleField;
this.base(newKey, val);
}
IntegerField.prototype = new DoubleField();
IntegerField.prototype.constructor = IntegerField;
var f = new Field('keyfield', 'valField');
var d = new DoubleField('keydouble', 'valDouble');
var i = new IntegerField('keyinteger');
var res = f.isEmtpy();
对 f.isEmpty 的调用失败了?为什么?对 d.isEmpty 或 i.isEmpty 的调用可以正常工作。
我无法意识到我做错了什么。任何帮助将非常感激!