实现继承的两种方式 call/apply 和 prototype
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html";charset="gbk"/ >
<script type="text/javascript" >
/*function Animal(){
this.s="animal";
}
function Cat(){
Animal.call(this);
this.name="cat";
}
var animal=new Animal();
var cat=new Cat;
alert(cat.s);*/ animal
function Animal(){}
Animal.prototype.s="animal";
function Cat(){
this.name="cat";
}
Cat.prototype=Animal.prototype;
var animal=new Animal();
var cat=new Cat;
alert(cat.s); animal
</script>
</head>
<body>
</body>
</html>

浙公网安备 33010602011771号