构造函数案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>王者荣耀构造函数</title>
<script>
function Hero(name,type,blood,attack) {
this.name = name;
this.type = type;
this.blood = blood;
this.attack = function (attack) {
console.log(attack);
}
}
var lianpo = new Hero('廉颇','力量型','500血量');
console.log(lianpo.name);
console.log(lianpo.type);
console.log(lianpo.blood);
lianpo.attack('攻击方式:近战');
var houyi = new Hero('后羿','射手型','100血量');
console.log(houyi.name);
console.log(houyi.type);
console.log(houyi.blood);
houyi.attack('攻击:远程');
</script>
</head>
<body>
</body>
</html>