<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>title</title> <script> function Person(age, sex) { this.age = age;//年龄 this.sex = sex; // this.eat = function () { // console.log("构造函数中的吃"); // }; } Person.prototype.sex = "女"; Person.prototype.eat = function () { console.log("原型对象中的吃"); }; var per = new Person(20, "男"); console.log(per.sex);//男 实例化的属性或方法,如今实例对象里面找 per.eat(); //"原型对象中的吃" 实例对象中找不到的时候,再去原型对象中找 console.dir(per); </script> </head> <body> </body> </html>