创建好的对象,我们是不能随便添加方法或者属性的,但是有时候是迫不得已的修改他人的对象但是还不能破坏其对象的内容。这个时候,我们就用到了继承。

<!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>Document</title>
</head>
<body>
<script>
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
Person.prototype.nationality = "English";
Person.prototype.name = function() {
return this.firstName + " " + this.lastName;
};
var demo = new Person('wenjun','huo',12,'嘻哈')
console.log(demo.nationality)
console.log(demo.name())
</script>
</body>
</html>