- 注册时间
- 2016-5-5
- 最后登录
- 2016-5-5
- 阅读权限
- 20
- 积分
- 6
- 精华
- 0
- 帖子
- 2

|
本帖最后由 遥远的眼眸 于 2016-5-5 10:27 编辑
大家好,我是一个新手。刚看到书中第17页。在
var proto=this.constructor.prototype;
if(!proto[prop]){
这两行均会报错。。怎么回事啊?
另外, proto[prop]["super"]=PeopleClass.prototype;这一行是什么意思啊?
function PeopleClass(){
this.type="人";
};
PeopleClass.prototype={
getType:function(){
alert("这是一个人");
}
};
function StudentClass(name,sex){
PeopleClass.apply(this,arguments);
var prop;
for(prop in PeopleClass.prototype){
var proto=this.constructor.prototype;
if(!proto[prop]){
proto[prop]=PeopleClass.prototype[prop];
}
proto[prop]["super"]=PeopleClass.prototype;
}
this.name=name;
this.sex=sex;
};
var stu=new StudentClass("lufy","男");
alert(stu.type);
stu.getType(); |
|