UNPKG

0216tool_xiaoye

Version:

叶永洁自定义工具函数库

38 lines (33 loc) 1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>手写继承</title> </head> <body> <script> function Person (name,age){ console.log('person') this.name = name this.age = age } Person.prototype.sayName = function (){ console.log(`我的名字是${this.name}`) } //将子类的原型对象指向父类 Student.prototype = new Person() //修改子类的构造器指向自身 Student.prototype.constructor = Student function Student (name,age,price){ //借用父类的构造函数 Person.call(this,name,age) this.price = price } let s = new Student('叶',20,200000) console.log(s) console.log(s.constructor) s.sayName() </script> </body> </html>