代码如下:
批量实现面向对象的实例 window.onload = function(){
function Person(name,age){
this.name = name;
this.age = age;
}
Person.prototype.showName = function(){
alert(this.name);
};
function extend(parent,child,method){
function a(){
parent.apply(this,arguments);
child.apply(this,arguments);
};
for(var i in parent.prototype){
a.prototype[i]=parent.prototype[i];
}
for(var i in method){
a.prototype[i] = method[i];
}
return a;
};//参数为父级构造函数,子级构造函数,子级方法
var int = extend(Person,function(name,age,job){
this.job = job;
},
{
showjob:function(){
alert(this.job);
}
}
);
var oc=new int('侠客',24,'工作');
oc.showjob();
}
script>
面向对象继承实例
开始展示批量实现面向对象的实例
下载本文