继承是一种关系,父类与子类的继承关系,通过原型来实现继承,继承就是为了数据共享.
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
function Person(name,money){
this.name=name;
this.money=money;
}
Person.prototype.play=function(){
console.log("会打篮球");
}
var per = new Person("小明","100块");
function Son(score){
this.score=score;
}
Son.prototype=new Person("小小明","100块");
Son.prototype.study=function(){
console.log("踢足球");
}
var son=new Son("考100分");
console.log(son.name,son.money,son.score);
son.study();
son.play();
</script>
</body>
</html>