<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
//继承的作用:精简代码
function Dad (name,house,car,money) {
this.name = name;
this.house = house;
this.car = car;
this.money = money;
this.sayName = function () {
alert(this.name);
}
this.hobby = function () {
alert("轰趴,飙车");
}
}
Dad.prototype.fight = function () {
alert("打架");
}
function Son (name,house,car,money) {
this.job = "吃喝玩乐";
this.name = name;
//继承使用call和apply
// Dad.call(this,name,house,car,money);
Dad.apply(this,arguments)
}
// Son.prototype = Dad.prototype; 公用地址,任意改变都会改变
Son.prototype = new Dad();
Son.prototype.constructor = Son;
var son1 = new Son("大儿子","复式别墅","宝马",1000000000000000000000);
alert(son1.car);
console.log(son1);
son1.fight();
</script>
</html>
网友评论