<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>借用父构造函数继承属性</title> </head> <body> <script> // 借用父构造函数继承属性 //1.父构造函数 function Father(name,age) { this.name = name; this.age =age; } //2.子构造函数 function Son(name,age) { //this指向子构造函数的实例 Father.call(this,name,age) } var son = new Son('张三',18); console.log(son) </script> </body> </html>
运行结果