js对象及prototype使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h3>js对象</h3>
<p id="demo"></p>
<script>
function Person(first, last, age, eye){
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyecolor = eye;
}
Person.prototype.nationality = "Chinese";
var Me = new Person("John", "Doe", 19, "black");
document.getElementById("demo").innerHTML = "我的国籍是" +Me.nationality;
</script>
</body>
</html>
prototype可以给对象添加新的方法
没加就是undefined