<script type="text/javascript">
function classA(str){
this.str=str;
this.printstr=function(){
document.write(this.str);
document.write("<br>");
}
this.getstr=function(){
return this.str;
}
}
function classB(name,str){
//下面这两句代码相当于将classA代码体中的内容搬到这里
this.newMethod1=classA;
this.newMethod1(str);
//注意,这里的写法
delete this.newMethod1;
//新的方法和属性的定义须在删除了newMethod之后定义,因为可能覆盖超类的属性和方法。
this.name=name;
this.sayName=function(){
document.write(this.name);
document.write("<br>");
}
}
var a=new classB("Amy","helloworld");
a.printstr();
alert(a.getstr());
a.sayName();
</script>
function ClassZ() {
this.newMethod = ClassX;
this.newMethod();
delete this.newMethod;
this.newMethod = ClassY;
this.newMethod();
delete this.newMethod;
}
<script type="text/javascript">
function classA(str){
this.str=str;
this.printstr=function(){
document.write(this.str);
document.write("<br>");
}
this.getstr=function(){
return this.str;
}
}
function classB(name,str){
//利用call方法实现继承
classA.call(this,str);
this.name=name;
this.sayName=function(){
document.write(this.name);
document.write("<br>");
}
}
var a=new classB("Amy","helloworld");
a.printstr();
alert(a.getstr());
a.sayName();
</script>
<script type="text/javascript">
function cA(){};
cA.prototype.name="John";
cA.prototype.sayName=function(){
document.write(this.name);
document.write("<br>");
}
function cB(){};
cB.prototype=new cA();
cB.prototype.age=23;
cB.prototype.sayAge=function(){
document.write(this.age);
document.write("<br>");
}
var objB=new cB();
objB.sayAge();
objB.sayName();
document.write("is objB the instance of cA "+(objB instanceof cA));
document.write("<br>");
document.write("is objB the instance of cB "+(objB instanceof cB));
document.write("<br>");
</script>
<script type="text/javascript">
function cA(name){
this.name=name;
};
cA.prototype.sayName=function(){
document.write(this.name);
document.write("<br>");
}
function cB(name,age){
cA.call(this,name);
this.age=age;
};
cB.prototype=new cA();
cB.prototype.sayAge=function(){
document.write(this.age);
document.write("<br>");
}
var objB=new cB("Alan",27);
objB.sayName();
objB.sayAge();
document.write("is objB the instance of cA "+(objB instanceof cA));
document.write("<br>");
document.write("is objB the instance of cB "+(objB instanceof cB));
document.write("<br>");
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有