function extend(subClass,superClass){
var F = function(){};
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.constructor = subClass;
}
function Person(name){
this.name = name;
}
Person.prototype.getName = function(){
return this.name;
}
function Author(name,books){
Person.call(this,name);
this.books = books;
}
Author.prototype.getBooks = function(){
return this.books;
}
extend(Author,Person);
var p = new Person("张三");
var a = new Author("刘畅");
console.log(p.getName());
console.log(a.getName());
extends in javascript
sun_weitao2024-09-16 11:53
相关推荐
m0_631270408 分钟前
标准C++(二)Zhen (Evan) Wang9 分钟前
What is the new in C#11?0224号比邻星15 分钟前
[C语言]第十节 函数栈帧的创建和销毁一基础知识到高级技巧的全景探索Jason-河山1 小时前
「铭记历史 珍爱和平」勿忘9.18!martian6651 小时前
学懂C++(六十):C++ 11、C++ 14、C++ 17、C++ 20新特性大总结(万字详解大全)国王不在家1 小时前
keyof和inferzhangbin_2371 小时前
【Python机器学习】NLP信息提取——命名实体与关系猿大撒1 小时前
Spring-data-redis帅过二硕ฅ2 小时前
uniapp点击跳转到对应位置Kerwin要坚持日更2 小时前
Java小白一文讲清Java中集合相关的知识点(九)