标签:
题目一:
function inheritPrototype(SubType,SuperType){
var prototype;
if(typeof Object.create===‘function‘){
prototype=Object.create(SuperType.prototype);
}else{
funciont W(){};
W.prototype=SuperType.prototype;
prototype=new W();
}
prototype.constructor=SubType;
Student.prototype=prototype;
}
inheritPrototype(Student,Person);
题目二,感觉给出了写法就是可以用来回答题目二的了。不过,还要优化的话,我想应该是这里
Person.prototype = {
getName : function() {
return this.name;
}
}
这里重新定义了原型对象,覆盖了原来的constructor属性,可以把它定义回去。就是这样
Person.prototype = {
constructor:Person,
getName : function() {
return this.name;
}
}
标签:
原文地址:http://www.cnblogs.com/LuckyWinty/p/5861618.html