extends in javascript

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());
相关推荐
m0_631270408 分钟前
标准C++(二)
开发语言·c++·算法
Zhen (Evan) Wang9 分钟前
What is the new in C#11?
开发语言·c#
0224号比邻星15 分钟前
[C语言]第十节 函数栈帧的创建和销毁一基础知识到高级技巧的全景探索
c语言·开发语言
Jason-河山1 小时前
「铭记历史 珍爱和平」勿忘9.18!
前端
martian6651 小时前
学懂C++(六十):C++ 11、C++ 14、C++ 17、C++ 20新特性大总结(万字详解大全)
开发语言·c++·c++20
国王不在家1 小时前
keyof和infer
前端
zhangbin_2371 小时前
【Python机器学习】NLP信息提取——命名实体与关系
开发语言·人工智能·python·深度学习·机器学习·自然语言处理
猿大撒1 小时前
Spring-data-redis
前端·bootstrap·html
帅过二硕ฅ2 小时前
uniapp点击跳转到对应位置
前端·javascript·uni-app
Kerwin要坚持日更2 小时前
Java小白一文讲清Java中集合相关的知识点(九)
java·开发语言