<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<title></title></head><body><script> ???function Person(name, age, sex) { ???????this.name = name; ???????this.age = age; ???????this.sex = sex; ???} ???//使用原型添加方法 ???Person.prototype = { ???????//手动修改构造器的指向 ???????constructor: Person, ???????eat: function () { ???????????console.log(this.name + "在吃饭"); ???????????this.study(); ???????}, ???????study: function () { ???????????console.log(this.name + "在学习"); ???????????this.run(); ???????}, ???????run: function () { ???????????console.log(this.name + "在跑步"); ???????} ???}; ???//实例化 ???var per = new Person("Andy", 18, "男"); ???per.eat(); ???//原型中的方法是可以相互访问的</script></body></html>
JS高级----------------->原型中的方法是可以相互访问的
原文地址:https://www.cnblogs.com/cuilichao/p/9527583.html