<!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>