<html><head> ???<meta charset="UTF-8"> ???<title>原型扩展和函数继承</title></head><body><script type="text/javascript">// 定义了Person类var Person = function(name){ ???this.name = name; ???this.say = function(content){ ???????console.log(this.name + " say: " + content); ???}}// 实例化var person = new Person("lay");// 调用函数person.say("I‘m a person");// 定义了Student类var Student = function(name){ ???// 调用构造函数,继承Person类 ???Person.call(this, name);}// 实例化var student = new Student("marry");student.say("I‘m a student");// 原型扩展函数Student.prototype.jump = function(){ ???console.log("I‘m jumping...");}// 调用函数student.jump();</script></body></html>
JS原型扩展和函数继承
原文地址:https://www.cnblogs.com/lay2017/p/8232399.html