//父类
function ParentClass() {
this.className = "ParentClass";
this.auth = "Auth";
this.version = "V1.0";
this.parentClassInfo = function () {
return this.className + "\n" + this.auth + "\n" + this.version;
}
}
//子类
//1、prototype继承
function ChildClassByPrototype() {
this.date = "2013-07-26";
this.classInfo = function () {
return this.parentClassInfo() + "\n" + this.date;
}
}
ChildClassByPrototype.prototype = new ParentClass();
var cctest1 = new ChildClassByPrototype();
cctest1.parentClassInfo();
cctest1.classInfo();
//2、apply继承
function ChildClassByApply() {
ParentClass.apply(this, new Array());
//ParentClass.apply(this, []);
this.date = "2013-07-26";
this.classInfo = function () {
return this.parentClassInfo() + "\n" + this.date;
}
}
//3、call+prototype继承
function ChildClassByCall() {
ParentClass.call(this, arguments);
this.date = "2013-07-26";
this.classInfo = function () {
return this.parentClassInfo() + "\n" + this.date;
}
}
ChildClassByCall.prototype = new ParentClass();
function ParentClass(className, auth, version) {
this.className = className;
this.auth = auth;
this.version = version;
this.parentClassInfo = function () {
return this.className + "\n" + this.auth + "\n" + this.version;
}
}
function ChildClassByApply(className, auth, version) {
ParentClass.apply(this, [className, auth, version]);
this.date = "2013-07-26";
this.classInfo = function () {
return this.parentClassInfo() + "\n" + this.date;
}
}
function ChildClassByCall(className, auth, version) {
ParentClass.call(this, arguments[0], arguments[1], arguments[2]);
//ParentClass.call(this, className, auth, version);
this.date = "2013-07-26";
this.classInfo = function () {
return this.parentClassInfo() + "\n" + this.date;
}
}
ChildClassByCall.prototype = new ParentClass();
var cctest2 = new ChildClassByApply("ParentClass", "Auth", "V1.0");
var cctest3 = new ChildClassByCall("ParentClass", "Auth", "V1.0");
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有