<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>构造继承</title>
</head>
<body>
<script>
/*
call 是以对象列表的方式进行传参
apply 使用数组的方式进行传参
*/
/*
不能继承原型方法
*/
function Animal(category) {
this.category = category || "Animal";
this.run = function () {
console.log("Animal run");
}
}
Animal.prototype.walk = function () {
console.log("Animal walk");
}
function Dog(category, name) {
Animal.call(this, category);
// Animal.apply(this, [category]);
this.name = name || 'dog';
this.type = 'dog';
}
var dog = new Dog("dog", "小白");
console.log(dog);
</script>
</body>
</html>
网友评论