<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JS类的继承的实现</title>
<script type="text/JavaScript">
//定义父类及公有、私有、静态属性及方法
function parent(){
var pname = "private";//私有属性
var pfun = function(){//私有方法
console.log("调用类的私有方法");
}
this.getName=function(name){//公有方法
this.name = name;//公有属性
return pname+"私有属性+公有属性"+this.name+"调用类的共有方法";
}
}
//定义静态属性及方法
parent.staticPro = "static property";
parent.staticFun = function(){
var str = "invoke class's static function";
return str;
}
//方法1 原型链继承
function childOne(){};
childOne.prototype = new parent();
//方法2 call/apply继承
function childTwo(){
parent.call(this);
}
function init(){
var c1 = new childOne();
console.log(c1.getName("child1"));//
console.log(c1.name);
var c2 = new childTwo();
console.log(c2.getName("child2"));
console.log(c2.name);
console.log(parent.staticPro);
console.log(parent.staticFun());
}
</script>
</head>
<body onload="init();">
<header>页眉</header>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有