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