js继承
1.apply继承
function Anmail(name,age){
this.name=name;
this.age=age;
this.eat=function(){
alert("Ok")
}
}
function dog(name,age){
Anmail.apply(this, [name,age])
}
var d=new dog();
d.eat()
2.原型继承
function Anmail(name,age){
this.name=name;
this.age=age;
this.eat=function(){
alert("Ok")
}
}
function dog(name,age){
Anmail.apply(this, [name,age])
}
dog.prototype=Anmail;
var d=new dog();
d.eat()
2.多态
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
</body>
<script type="text/javascript">
function amil() {
this.say = function() {
alert("dongwu");
}
}
function dog() {
this.say = function() {
alert("dog");
}
dog.prototype=new amil();
}
function cat() {
this.say = function() {
alert("cat");
}
}
cat.prototype=new cat();
function say(anm) {
if(anm instanceof amil){
anm.say;
}
}
var d=new dog();
say(d);
</script>
</html>