高程3(P163)上关于原型链的一段代码,我把输出换成getSubValue()后,试着交换其中两段代码的顺序,结果报错,怎么都想不通为什么??
function superType(){
this.property = true;
}
superType.prototype.getSuperValue = function(){
return this.property;
};
function subType(){
this.subproperty = false;
}
// subType.prototype.getSubValue = function(){
// return this.subproperty;
// };
//Uncaught TypeError: instance.getSubValue is not a function
subType.prototype = new superType();
subType.prototype.getSubValue = function(){
return this.subproperty;
}; // 此段代码与换到上面注释的位置则出错
var instance = new subType();
console.log(instance.getSubValue());
看看《高程》166页,有对你这个问题进行说明。