<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>apply 使用</title>
</head>
<body>
<script>
// 实现继承
function Animal(name){
this.name = name;
this.showName = function(){
alert(this.name);
}
}
function Cat(name){
Animal.apply(this, [name]);
}
var cat = new Cat("Black Cat");
cat.showName();
// 多重继承
function Class10(){
this.showSub = function (a,b){
alert(a-b);
}
}
function Class11(){
this.showAdd = function (a,b){
alert(a+b);
}
}
function Class2(){
Class10.apply(this);
Class11.apply(this);
}
var dd = new Class2();
dd.showSub(5,2);
dd.showAdd(5,2);
</script>
</body>
</html>
apply 使用
最新推荐文章于 2023-03-03 21:11:18 发布