<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<title></title></head><body><script> ???function Student(name, age, sex) { ???????this.name = name; ???????this.age = age; ???????this.sex = sex; ???} ???//简单的原型写法 ???Student.prototype = { ???????//手动修改构造器的指向 ???????constructor: Student, ???????height: 188, ???????width: 55, ???????study: function () { ???????????return this.name + "在学习"; ???????}, ???????eat: function () { ???????????return this.name + "在吃饭"; ???????} ???}; ???var stu = new Student("Andy", 18, "男"); ???console.log(stu.study()); ???console.log(stu.eat()); ???console.dir(stu); ???console.dir(Student); ???//注意需要手动修改构造器的指向</script></body></html>
JS高级----------------->原型简单的写法(注意手动修改构造器的指向)
原文地址:https://www.cnblogs.com/cuilichao/p/9527581.html