函数的继承

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>函数的继承</title>

<script type="text/javascript">

//父类

function Fclass(name, age){

this.name = name;

this.age = age;

}

Fclass.prototype.showName = function(){

alert(this.name);

}

Fclass.prototype.showAge = function(){

alert(this.age);

}

//子类

function Sclass(name, age, job){

//方法的继承(父类的实例赋给子类的原型)

Fclass.call(this,name,age);

this.job = job;

}

Sclass.prototype = new Fclass();

Sclass.prototype.showJob =  function(){

alert(this.job);

}

var Driver = new Sclass('tom',18,'老司机');

Driver.showName();

Driver.showJob();

Driver.showAge();

</script>

</head>

<body>

</body>

</html>

推荐阅读更多精彩内容