JS高级----------------->原型添加方法解决数据共享的问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> function Person(name, sex) { this.name = name; this.sex = sex; } //通过原型来添加方法,解决数据共享的问题,节省内存空间 Person.prototype.eat = function () { console.log(this.name + "在吃饭") }; var per1 = new Person("Join", "男"); var per2 = new Person("Andy", "女"); per1.eat(); per2.eat(); console.log(per1.eat == per2.eat); </script> </body> </html>